Unable to run JAR file (created in Eclipse)

Posted by Trist on Stack Overflow See other posts from Stack Overflow or by Trist
Published on 2010-04-27T12:17:13Z Indexed on 2010/05/21 21:40 UTC
Read the original article Hit count: 146

Filed under:
|
|
|

I hate starting a post with this but I'm new to Java... I've followed this tutorial to create a socket server (mines in Eclipse). I can run the server within Eclipse, all is well. But when I try to export the project I can't figure out how to run it. I keep getting this error (it varies depending on how I run it)

Exception in thread "main" java.lang.NoClassDefFoundError: xsocketserver/Main
Caused by: java.lang.ClassNotFoundException: xsocketserver.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

I've read this problem relates to class paths being set. I've tried the following:

java -cp libs/xSocket-2.8.12.jar xsocketserver.Main
java -jar xSocketServer.jar    
java -classpath xSocketServer:xSocketServer/libs/xSocket-2.8.12.jar xsocketserver.Main

plus many others. The file structure within the JAR is as follows:

xSocketServer.jar
    -> xsocketserver
        -> Main.class
        -> xSocketDataHandler.class
    -> META-INF
        -> MANIFEST.MF
    -> libs
        -> xSocket-2.8.12.jar

Incidentally I've tried adding my own manifest file which contains the Class-Path but when I check it it always reads:

Manifest-Version: 1.0
Main-Class: xsocketserver.Main

I'm guessing this is a common problem based on the number of hits I've seen in Google but I can't fathom what I'm doing wrong. Wrong Export settings maybe??

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse