NoClassDefFoundError inside a jar

I have a class that is in the com.toptur.sysTray package, all it does is the boot system tray, it does not use any external packages. I am creating a SysTray object to set up the taskbar. Everthing builds great. I can run the application from the command line and install systray. But when I try to create a jar from class files and run it, I get a NoClassDefFoundError.

The package and its class files are in the bank; my application does not use external ant containers. just classes defined by java.

And if you create a .exe file from a jar, it starts working again without errors.

How can I track this?

<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 am creating a jar file from an ant target using the above code. The driver program is not included in the package. its located in gotacan.java

I run it with java -jar toptur.jar

the rest of the program works, it only throws an exception when I try to use this package.

+4
source share
4 answers

The Class not Found exception excludes the name of the class it is looking for.

Since you only have a jar on the way to classes, it should be in the bank, but it is not. Find out why, possible reasons:

  • the class file is not where it belongs when ant creates the package
  • the directory structure representing the package name is not implemented where all other classes are rooted
  • the place where the class file belongs is not included in the list of files placed in the ant bank.

Luck

Note: banks are only zip files with a ratio, so you can use any zip program to check which files are actually there.

+3
source

I assume that your manifest either does not have the main class designation, or the class path, or the jar does not contain the path to the package directory.

A tutorial can help. Your sounds are simple enough, where is a small thing that you missed.

UPDATE: the name of the main class must be the fully qualified name of the class, including the full package. If your class is in the package, then where you did wrong.

+1
source

This probably depends on the JRE, in which you run the program with the JVM, which you use to build, and to build .exe with.

SysTray functionality is completely new (Java6), so if you have an old JRE or JVM in the system path at startup

 java -jar toptur.jar 

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

0
source

I had a similar problem when I tried to create a jar using ant for an open source project.

I contacted the authors and instead they used eclipse to export jar. I calculated what they suggested and found a clear difference in the size of the jar files. I did not spend time to determine the difference that made it work, and the other did not. However, you can use a similar process for your material to work properly. If so, perhaps you can look at the difference and share the result with us :)

Below is a link to my problem and solution: Xerces-for-Android NoClassDefFoundError when using Jar instead of source code

0
source

Source: https://habr.com/ru/post/1285848/


All Articles