简体   繁体   English

Java jar问题

[英]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... 我对Java的了解相当生疏,但是我被迫使用它并且遇到了一些可怕的类路径问题......

I'm trying to import a jwebserver class. 我正在尝试导入一个jwebserver类。 It should be straightforward, but I don't know how! 它应该是直截了当的,但我不知道怎么做!

Here is my server.java file: 这是我的server.java文件:

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输出:

>>> ls
bin  conf  libs  logs  server.java

and here is an ls ./libs output: 这是一个ls ./libs输出:

>>> 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, 提前谢谢了,

jWebSocketServer-0.9.5.jar probably depends on jWebSocketCore.0.9.5.jar. jWebSocketServer-0.9.5.jar可能依赖于jWebSocketCore.0.9.5.jar。 So you need to add them both in the classpath command: 所以你需要在classpath命令中添加它们:

javac -classpath ./libs/jWebSocketServer-0.9.5.jar;./libs/jWebSocketCore-0.9.5.jar; server.java

After a quick look at jWebSocket, the problem might just be case sensitivity in your package name. 快速浏览一下jWebSocket后,问题可能只是包名称中的区分大小写。

Try import org.jwebsocket.*; 尝试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 ) 另一方面,让它做一些有用的事情...... :)尝试网站上的JavaDocs( jWebSocket网站上的Java / JS Docs链接)


Update: There's nothing actually in the package org.jwebsocket. 更新:包org.jwebsocket中实际上没有任何内容。 There is a class in org.jwebsocket.console, so try import org.jwebsocket.console.*; org.jwebsocket.console中有一个类,所以请尝试import org.jwebsocket.console.*;

Try adding all jars on your libs folder to your compilation classpath: 尝试将libs文件夹中的所有jar添加到编译类路径中:

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

Also, please do consider the possibility of using an IDE (such as Eclipse ) to compile your code samples. 另外,请考虑使用IDE(例如Eclipse )编译代码示例的可能性。 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. 您可以将所有jWebSocket库添加到项目中并编译代码示例。 No need to deal with classpath issues manually. 无需手动处理类路径问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM