NoClassDefFoundError while working with the jar

I get an exception "no class definition found" when I try to run my application on Windows (it works fine on OS X). The classes that the JVM complains about are my classes (no third-party jars are required). When I unzip the files inside the jar, all the files are present, including the ones JVMm complains about.

A bank is created using the following task:

<target name="jar" depends="">
<jar destfile="build/app.jar" > 
  <manifest>
    <attribute name="Built-By" value="hamza"/>
    <attribute name="Main-Class" value="com.hamza.driver.ui"/>
<attribute name="Class-Path" value="./"/>
  </manifest>
  <fileset dir="build">
    <include name="**/*.class"/>
<include name="**/*.png"/>
<include name="**/*.xpi"/>
<include name="**/*.html"/>
<exclude name="**/*.jar"/>
  </fileset>
</jar>

I can not understand what is causing the problem. If I unzip the jar and run the jar from the directory into which I unpacked the class, everything works fine. So, I assume that all the necessary files are inside the jar.

EDIT: com.hamza.driver.uiis the class in the package with the name com.hamza.driverthat it has main.

"app.jar", "java -jar app.jar", X, Windows.

app.jar "java -jar app.jar", .

2: :

Exception in thread "main" java.lang.NoClassDefFoundError: com/hamza/gui/tr
ansfer/ClipboardTransferHandle
        at com.hamza.driver.ui.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.hamza.gui.transfer.Clipboa
rdTransferHandle
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        ... 1 more

ClipboardTransferHandle.class .

3: :

import java.util.logging.Logger;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.Toolkit;
import java.io.IOException;

, ClipboardTransferHandle , , , , . GUI , , ; , , NoClassDefFound, , .

+3
4

, ,

JAR "C:\java\apps\appli.jar", : reference "lib/other.jar", "C:\java\apps\lib\" "other.jar". JAR "lib/other.jar".

: -

  • , "".
  • Java Runnable JAR File JAR .
  • , " " , .. ( JAR).
  • "", JAR , JARS, .
  • , , java -jar abc.jar

    , , JARS, , JAR. java.lang.NoClassDefFoundError..

    ... , !

+2

? Main-Class - com.hamza.driver.ui ?

+1

, NoClassDefFoundError ( - ...) , , (- > ), , java , .

, ( : OSGi), . OSGi - . , , OS-X, Window. , Java.

!

Edit

SO, , , , , :

NoClassDefFound jar

NoClassDefFoundError jar

2

, . , :

NoClassDefFoundError java.exe -jar... ?

+1
source

Did you specify a new jar in your classpath (java -cp .; new.jar MainClass.class)?

0
source

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


All Articles