java.lang.ClassNotFoundException : org. glassfish.jersey.client.JerseyClientBuilder

标签 java eclipse maven jersey

嗨,我正在使用以下 Maven 依赖项。当我在 Eclipse 中运行该应用程序时,它工作正常。但是当我将应用程序部署为 jar 文件时,它会抛出以下错误。

Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
 at java.net.URLClassLoader.findClass(Unknown Source)

以下是我的 Maven 依赖文件。

<dependencies>  
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey.client.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>${jersey.client.version}</version>
        </dependency>

        <!-- http://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

    </dependencies>

    <properties>
        <jersey.client.version>2.21</jersey.client.version>
    </properties>

<dependencies>  

对此有任何帮助......我浏览了以下链接,但它对我没有帮助。

running standalone java executable in eclipse results in NoClassDefFound

最佳答案

如果您只分发单个 jar(不是 fat-jar/uber-jar),您需要为其提供类路径,这是运行它所需的所有库 jar。

在你的情况下,这将是这样的:

java -jar my.jar -cp $HOME/.m2/repository/org/glassfish/jersey/core/jersey-client/2.21/jersey-client-2.21.jar

: 之后,您需要添加您拥有的所有其他依赖项。

另一种选择是使用例如用于构建 uber jar 的程序集插件(包含所有其他 jar、库和代码的 jar):http://maven.apache.org/plugins/maven-assembly-plugin/usage.html :

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
       </plugin>
    </plugins>
</build>

然后使用:mvn clean package assembly:single构建jar,看到现在target中有两个jar,较大的一个是uber jar您可以分发。

关于java.lang.ClassNotFoundException : org. glassfish.jersey.client.JerseyClientBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39198911/

相关文章:

java - 为什么在 Eclipse IDE 中不产生编译时异常除以零?

maven - 错误:无法找到或加载主类org.apache.mahout.driver.MahoutDriver

java - Eclipse Tycho 无法解析正确的依赖关系

java - 在 Spring Webflow 中映射对象时出现 FlowInputMappingException

java - IllegalStateException java httpclient

java - 使用嵌套 For 循环初始化 2D 数组的值

java - 如何在 Jhipster Gateway 中代理请求?

java - "A JNI Error has occurred"对于程序的一个实例,而不是另一个

java - 将 Eclipse JDT ITypeBinding 转换为类型

java - org.hibernate.MappingException : Unknown entity: java. lang.Integer