views:

1132

answers:

3

I have a class that that sits in a package called com.toptur.sysTray all it does is load system tray it does not use any external packages. i create a SysTray object to install the system tray. Everthing builds fine. i can run the application from command line and systray gets installed. But when i try to create a jar from the class files and run it i get NoClassDefFoundError.

Package and its class files are in the jar my application does not use ant external jars. just classes provied by java.

And if build a .exe file out of the jar, it starts to work again without any errors.

How can i track this down?

  <target name="jar" depends="">
  <jar destfile="build/toptur.jar" > 
    <manifest>
      <attribute name="Built-By" value="Toptur"/>
      <attribute name="Main-Class" value="gotacan"/>
    </manifest>
    <fileset dir="build">
       <include name="**/*.class"/>
    <include name="**/*.png"/>
<exclude name="**/*.jar"/>
  </fileset>
</jar>

i create the jar file from a ant target using above code. driver program is not in a package. its located in gotacan.java

I run it using java -jar toptur.jar

rest of the program works it only throws exception when i try to use that package.

A: 

I'm guessing that your manifest is either missing the main class designation, a classpath, or the jar doesn't include the package directory path properly.

A tutorial might help. Yours sounds simple enough where it's a small thing that you've overlooked.

UPDATE: The name of the main class has to be the fully resolved class name, including the full package. If your class is in a package, that's where you went wrong.

duffymo
main cass is not in a package. rest of the components are. every other class is resolved fine except this single one. all packages are in com.toptur folder
+1  A: 

The Class not Found Exception should mention the name of the class it is looking for.

Since you have only the jar on the classpath it should be in the jar, but it isn't. Figure out why, possible reasons:

  • the class file is not where it belongs when ant builds the package
  • the directory structure representing the package name is not rooted where all the other classes are rooted
  • the place where the class file belongs is not included in the list of files to put into the jar by ant.

Good Luck

Note: jars are just zip files with an attitude, so you can use any zip-program to check what files are actually in there.

Jens Schauder
He can also just use jar xvf toptur.jar from the command line to extract the jar.
Daniel Nesbitt
true (assuming the parameters are correct) but few know this by heart, while almost every developer knows to use at least one zip tool
Jens Schauder
A: 

Probably depends on the JRE you run the program with against the JVM that you use it to build and to build the .exe with.

The SysTray functionality is quite new (Java6), so if you have some old JRE or JVM on the system path when you run

java -jar toptur.jar

It can find the class that you wrote, but not the classes that it uses from the JRE.

Maarten Winkels