×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

problems with a simple HelloWorld.jar

problems with a simple HelloWorld.jar

problems with a simple HelloWorld.jar

(OP)
I know such questions have been posted a lot, but I read the answers to some and still got the same problem:

I can`t produce a simple jar-File:

Typing ant jar results in:

Buildfile: build.xml
init:
compile:
jar:
  [jar] Warning: skipping jar archive AntHelloWorld\jar\HelloWorld.jar because no files were included.

BUILD SUCCESSFUL
Total time: 0 seconds

Typing java -jar jar/HelloWorld.jar results in:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld


In the HelloWorld.jar is only the Manifst.MF included, this looks like:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.6.0-b105 (Sun Microsystems Inc.)
Main-Class: HelloWorld

The HelloWorld.java is directly in the folder java.
The build.xml looks like:

<!-- name of your project, default target and starting point for all actions -->
<project name="AntHelloWorld" default="jar" basedir=".">
    <description>Test
        </description>
    
    <!-- setting global properties -->
    <property name="java" location="java"/>
    <property name="class" location="class"/>
    <property name="jar" location="jar"/>
    
        
    <!-- building temporary (= redundant!) directories -->
    <target name="init">
        <tstamp>
            <format property="TODAY_UK" pattern="MM-dd-yyyy" locale="en"/>
        </tstamp>
        <mkdir dir="$(class)"/>
        <mkdir dir="$(jar)"/>
    </target>
    

    <!-- generating .class files -->
    <target name="compile" depends="init">
        <javac srcdir="${java}" destdir="${class}">    
        </javac>
    </target>
    
    <!-- generating executable jar file -->
        <target name="jar" depends="compile">
            <jar jarfile="${jar}/HelloWorld.jar"
                basedir="$(class)"
                includes="**/*.class">
                <manifest>
                    <attribute name="Main-Class" value="HelloWorld"/>
                </manifest>
            </jar>
        </target>
    
    <!-- running the programm -->
    <target name="run" depends="jar">
        <java jar="${jar}/HelloWorld.jar" fork="true">
            </java>
    </target>
    
    <!-- deleting temporary (= redundant!) directories and content -->
            <target name="clean">
                <delete dir="${class}"/>
                <delete dir="${jar}"/>
            </target>
    
</project>    


Can somebody help me?  

RE: problems with a simple HelloWorld.jar

It may sound like a daft question, but can you confirm that the java file(s) compiled okay? If you do an ant compile do you get any .class files in the class directory?

Tim

RE: problems with a simple HelloWorld.jar

(OP)
Yes, of course, the HelloWorld.class is put in the folder class. To be sure, I just tried out ant compile (before I had deleted the .class file).

In the main-method of the HelloWorld.java is only an
System.out.println("HelloWorld");

RE: problems with a simple HelloWorld.jar

Mmmm. Try

CODE

<target name="jar" depends="compile">
   <jar jarfile="${jar}/HelloWorld.jar"
        basedir="${class}"
        includes="**/*.class">
      <manifest>
         <attribute name="Main-Class" value="HelloWorld"/>
      </manifest>
   </jar>
</target>

You need the curly braces instead of ordinary parentheses.

Tim

RE: problems with a simple HelloWorld.jar

(OP)

Thanks a lot!

It works now(with curly braces instead of ordinary parentheses)!

Ninca

RE: problems with a simple HelloWorld.jar

One tip, Ninca. I would have spotted that much sooner had you not posted the script in the colour you did. It's always best to put code and scripts in a post with the TGML code tags as I did in my last post above. Much easier on the eye.

Tim

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close