views:

113

answers:

3
+1  Q: 

Java jar problem

Hi,

My knowledge of Java is rather rusty, but I've been forced to use it and am having some terrible classpath troubles...

I'm trying to import a jwebserver class. It should be straightforward, but I don't know how!

Here is my server.java file:

import java.io.*;
import org.jWebSocket.*;

public class server
{
        public static void main(String args[])
        {
                System.out.println("Hello World!");
        }
}

And here is the error when I try to compile:

>>> javac -classpath ./libs/jWebSocketServer-0.9.5.jar server.java 
server.java:2: package org.jWebSocket does not exist
import org.jWebSocket.*;
^
1 error

Here is an ls output:

>>> ls
bin  conf  libs  logs  server.java

and here is an ls ./libs output:

>>> ls ./libs
commons-lang-2.5.jar
javolution-5.5.1.jar
json-2-RELEASE65.jar
jWebSocketAdmin-0.9.5.jar
jWebSocketCluster-0.9.5.jar
jWebSocketCore-0.9.5.jar
jWebSocketCustomServer-0.9.5.jar
jWebSocketFactory-0.9.5.jar
jWebSocketNettyEngine-0.9.5.jar
jWebSocketPlugins-0.9.5.jar
jWebSocketSamples-0.9.5.jar
jWebSocketServer-0.9.5.jar
jWebSocketSharedObjects-0.9.5.jar
jWebSocketTCPEngine-0.9.5.jar
jWebSocketTokenServer-0.9.5.jar
jWebSocketToolkit-0.9.5.jar
log4j-1.2.15.jar
netty-3.2.0.BETA1.jar
servlet-api-2.5-6.1.14.jar
slf4j-api-1.5.10.jar
slf4j-jdk14-1.5.10.jar

I'm hoping someone can help me here.

Many thanks in advance,

A: 

Try adding all jars on your libs folder to your compilation classpath:

$ javac -classpath ./libs/*.jar server.java

Also, please do consider the possibility of using an IDE (such as Eclipse) to compile your code samples. It will make your life way simpler than compiling everything by hand. You can just add all jWebSocket libraries to your project and compile your code sample. No need to deal with classpath issues manually.

Pablo Santa Cruz
Hi,Thanks for your reply. I tried that, but got the following error:javac: invalid flag: ./libs/javolution-5.5.1.jarUsage: javac <options> <source files>use -help for a list of possible optionsAlso, I'm not an IDE fan...
Eamorr
+2  A: 

jWebSocketServer-0.9.5.jar probably depends on jWebSocketCore.0.9.5.jar. So you need to add them both in the classpath command:

javac -classpath ./libs/jWebSocketServer-0.9.5.jar;./libs/jWebSocketCore-0.9.5.jar; server.java
Thierry-Dimitri Roy
Hi,Thanks for the reply. I tried that and it didn't work. Same error ;(
Eamorr
+2  A: 

After a quick look at jWebSocket, the problem might just be case sensitivity in your package name.

Try import org.jwebsocket.*;

That should get your code to compile. Getting it to do something useful, on the other hand... :) try the JavaDocs on the website (the Java/JS Docs link on the jWebSocket website)


Update: There's nothing actually in the package org.jwebsocket. There is a class in org.jwebsocket.console, so try import org.jwebsocket.console.*;

Brabster
Hi,Thanks for that.I tried changing the case and it didn't work: same error...
Eamorr
There are no classes in org.jwebsocket - the only class in the .jar is in org.jwebsocket.console. Try import org.jwebsocket.console.*
Brabster
Legend,It's working now...Thanks so much for that.
Eamorr