NoClassDefFoundError inside jar

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" > 
      <attribute name="Built-By" value="Toptur"/>
      <attribute name="Main-Class" value="gotacan"/>
    <fileset dir="build">
       <include name="**/*.class"/>
    <include name="**/*.png"/>
<exclude name="**/*.jar"/>

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

I run it using java -jar toptur.jar

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


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.

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.

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.

I had a similar issue when I was trying to make a jar using ant for an open source project.

I got in contact with the authors, and they used eclipse to export the jar instead. I mimiced what they suggested and found a clear difference in the size of the jar files. I did not spend the time to determine the difference which was causing one to work and the other to not. However you may be able to use a similar process to get your stuff working properly. If so, perhaps you can look at the difference and share the result with us :)

The following is a link to my problem and the solution: Xerces-for-Android NoClassDefFoundError When Using Jar Instead of Source Code

Need Your Help

How to log sql errors when restoring database from dump file

mysql logging error-handling restore

Pre-apologies for any duplication here but I swear I have researched (and learned a lot in the process).

Threaded SOAP requests in Python (Django) application?

python django soap multithreading asynchronous

I'm working with an application that needs to be make some time consuming SOAP requests (using suds, as it were). There are several instances where a user will change the state of an object and in...