Eamorr
Eamorr

Reputation: 10022

Java jar problem

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,

Upvotes: 1

Views: 1938

Answers (3)

brabster
brabster

Reputation: 43590

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.*;

Upvotes: 2

Thierry Roy
Thierry Roy

Reputation: 8512

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

Upvotes: 2

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181450

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.

Upvotes: 0

Related Questions