Maven的java.lang.noclassdeffounderror [英] java.lang.noclassdeffounderror for Maven

查看:86
本文介绍了Maven的java.lang.noclassdeffounderror的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Maven的新手,我最近创建了这个需要多值映射的程序.由于我没有jsr311-api.jar,因此我从网上下载了它,但是我不知道将它们放在哪里.我决定将其上传到apache-maven/lib文件夹中,并尝试运行该程序,但是它不起作用.这是我得到的错误.

I am new at Maven and I recently created this program that requires multivaluedmap. Since I did not have jsr311-api.jar, I downloaded it from online, but I have no clue where to place them. I decided to upload it onto the apache-maven/lib folder and tried to run the program, but it did not work. This is the error that I get.

Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/Mul
ivaluedMap
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.MultivaluedMap
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 7 more

我认为放错.jar文件会出错.预先感谢您的帮助.

I assumed that I'm getting errors from misplacing the .jar file. Thank you in advance for your help.

这是我目前拥有的pom文件: http://maven.apache.org/xsd/maven-4.0.0.xsd> 4.0.0

This is my pom file that I currently have: http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.test.api</groupId>
<artifactId>testing</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<name>testPlatform</name>

<properties>
    <source.version>1.7</source.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

    </plugins>
</build>

<dependencies>
    <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
    <!-- REST client -->
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.9.1</version>
    </dependency>

    <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>0.11</version>
 </dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>

    <!-- for deserialization -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.4</version>
    </dependency>



</dependencies>

推荐答案

我很确定我在这里知道您的问题.

I'm fairly sure that I know your problem here.

您正在使用Maven编译代码并制作一个jar文件.

You are using Maven to compile your code and make a jar files.

然后,您尝试使用某些Java命令行或其他命令从maven外部执行该jar文件.

Then you are trying to execute that jar file from outside maven with some java command line or another.

当Maven调用Java来编译代码时,它会将所有依赖项添加到类路径中.

When Maven calls Java to compile your code, it's adding all your dependencies to the classpath.

运行代码时不是.

您可以配置maven-dependency-plugin以写出具有所有依赖项的路径名的文本文件,然后可以使用它来构建命令行.或者您可以使用maven-surefire-plugin运行测试,或使用exec-maven-plugin仅启动一个类,或使用appassembler插件来构建具有依赖项和命令行包装的程序包,或...

You can configure the maven-dependency-plugin to write out a text file with the pathnames of all your dependencies, and then you can use that to build a command line. or you can use the maven-surefire-plugin to run tests, or the exec-maven-plugin to just launch a class, or the appassembler plugin to build a package with the dependencies and a command-line wrapper, or ...

这是使依赖性插件写出您的类路径的方法.

Here's how to make the dependency plugin write out your class path.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>build-classpath</id>
        <phase>generate-sources</phase>
        <goals>
           <goal>build-classpath</goal>
        </goals>
        <configuration>
         <outputFile>${project.build.directory}/classpath.txt</outputFile>
        </configuration>
      </execution>
    </executions>
  </plugin>

这篇关于Maven的java.lang.noclassdeffounderror的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆