Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with a simple HelloWorld.jar

Status
Not open for further replies.

Ninca

Programmer
Mar 9, 2007
3
0
0
DE
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?

 
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
 
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");
 
Mmmm. Try
Code:
<target name="jar" depends="compile">
   <jar jarfile="${jar}/HelloWorld.jar"
        basedir="[b]${class}[/b]"
        includes="**/*.class">
      <manifest>
         <attribute name="Main-Class" value="HelloWorld"/>
      </manifest>
   </jar>
</target>

You need the curly braces instead of ordinary parentheses.

Tim
 

Thanks a lot!

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

Ninca
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top