找到你要的答案

Q:Java Socket.IO missing dependency NoClassDefFoundError

Q:java socket.io NoClassDefFoundError失踪的依赖

Hi guys im pretty new to java. Coming from .NET, C++. I am trying to get my head over with an error that is killing me since days and i am unable to fix it.

I get this error when i try to run my .jar file

java.lang.NoClassDefFoundError: com/github/nkzawa/emitter/Emitter$Listener

I have no clue what else it needs, or why its not loading the engine.io-client.

Any help appreciated.

Edit:

Crashing code part:

    socket = IO.socket("http://blah.com:1234");
    socket.on(Socket.EVENT_CONNECT, new Emitter.Listener()
    {

    // ...

    });

pom.xml

<dependency>
        <groupId>com.github.nkzawa</groupId>
        <artifactId>socket.io-client</artifactId>
        <version>0.5.0</version>
    </dependency>

Is there any other way to make sure that these dependencies are shipped with the final jar file so i don't have dependency issues on the end-user's machine?

嗨我java很新。来自网络,C++。我试图让我的头与一个错误,这是杀害我,因为我无法修复它。

当我尝试运行我的JAR文件时,我得到这个错误

java.lang.NoClassDefFoundError: com/github/nkzawa/emitter/Emitter$Listener

我不知道还有什么需要,或为什么不加载engine.io-client。

任何帮助赞赏。

编辑:

崩溃代码部分:

    socket = IO.socket("http://blah.com:1234");
    socket.on(Socket.EVENT_CONNECT, new Emitter.Listener()
    {

    // ...

    });

pom.xml

<dependency>
        <groupId>com.github.nkzawa</groupId>
        <artifactId>socket.io-client</artifactId>
        <version>0.5.0</version>
    </dependency>

有没有其他的方法来确保这些依赖项与最终JAR文件一起传输,这样我就不会对最终用户的机器产生依赖性问题了?

answer1: 回答1:

When you compile C++ code, you have to give the compiler a list of (shared) libraries which your code depends on. In Java, you can specify a list of JARs which are added to the "classpath". Unlike C++, Java allows to change the classpath after the code has been compiled. So you can add additional elements or remove existing ones. In C++, you usually can replace the DLL file on disk but you need special tricks to get your code to load more DLLs or forget about ones that it was linked against.

This causes all kind of weird problems like the one which you experience right now: Eclipse builds the classpath for you, everything looks fine. You export the project as an executable JAR and suddenly, you have to do a lot of tedious work just to replicate a click of a button in the IDE.

The most simple way to get the classpath is to start your program in the IDE once, switch to the Debug perspective and check the properties of the process which Eclipse created. It will display the Java command line which it built. It's not a pretty sight.

Copy the whole thing into a .cmd file and use that to start your application.

You can also use Maven to create executable JARs with several options how to handle dependencies: How can I create an executable jar with dependencies using Maven?

当你编译C++代码,你必须给编译器列表(共享)库的代码依赖于。在java中,您可以指定一个列表的瓶是添加到“路径”。不像C++,java允许在代码被编译的变化路径。因此,您可以添加其他元素或删除现有的。在C++中,你通常可以在磁盘替换DLL文件,但是你需要特殊的技巧,让你的代码加载更多的DLL或忘记那是相连的。

这导致各种奇怪的问题,就像你现在的经验:月食为你创建的类路径中,一切看起来很好。你将项目导出为可执行jar和突然,你要做很多繁琐的工作只是复制点击IDE中的按钮。

获得路径的最简单方式就是启动你的程序在IDE中一次,切换到Debug透视图和检查的过程中,Eclipse创造性能。它会显示java命令行的建。这不是一个美丽的景象。

复制整个事情变成一个cmd文件用以启动应用程序。

你也可以使用Maven创建几个选项如何处理依赖执行罐:我如何创建一个依赖使用Maven执行jar吗?

answer2: 回答2:

Evidently a library is missing. An internet search will yield

<dependency>
    <groupId>com.github.nkzawa</groupId>
    <artifactId>engine.io-client</artifactId>
    <version>0.4.1</version>
</dependency>

Then check for the latest version here. Should accord a little with your other dependency to nkzawa.

显然图书馆丢失了。互联网搜索将收益

<dependency>
    <groupId>com.github.nkzawa</groupId>
    <artifactId>engine.io-client</artifactId>
    <version>0.4.1</version>
</dependency>

Then check for the latest version here. Should accord a little with your other dependency to nkzawa.

answer3: 回答3:

When I look at the pom file I see a number of dependencies that this artifact has. Just referring to this pom will make maven download those dependencies, but they won't be included in your build unless you're building a jar-with-dependencies.

当我看着POM文件我看到一些依赖,这件宝物。就是指这个POM将Maven下载这些依赖关系,但他们不会在你建立包括除非你建设依赖一罐。

answer4: 回答4:

I was using socket-io following version :

<dependency>
    <groupId>io.socket</groupId>
    <artifactId>socket.io-client</artifactId>
    <version>0.8.2</version>
</dependency>

I had to add the following dependencies to the runtime to get this working.

<dependency>
    <groupId>io.socket</groupId>
    <artifactId>engine.io-client</artifactId>
    <version>0.8.2</version>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp-ws</artifactId>
    <version>3.4.1</version>
</dependency>
<dependency>
    <groupId>com.squareup.okio</groupId>
    <artifactId>okio</artifactId>
    <version>1.11.0</version>
</dependency>

Refer to the pom.xml files to figure out the dependencies :

我是使用socket IO以下版本:

<dependency>
    <groupId>io.socket</groupId>
    <artifactId>socket.io-client</artifactId>
    <version>0.8.2</version>
</dependency>

我不得不添加下面的依赖关系到运行时得到这个工作。

<dependency>
    <groupId>io.socket</groupId>
    <artifactId>engine.io-client</artifactId>
    <version>0.8.2</version>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp-ws</artifactId>
    <version>3.4.1</version>
</dependency>
<dependency>
    <groupId>com.squareup.okio</groupId>
    <artifactId>okio</artifactId>
    <version>1.11.0</version>
</dependency>

参阅pom.xml文件找出依赖:

java  maven