开发者

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开发者_JS百科.*;
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,


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜