问题
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
I assumed that I'm getting errors from misplacing the .jar file. Thank you in advance for your help.
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>
回答1:
I'm fairly sure that I know your problem here.
You are using Maven to compile your code and make a jar files.
Then you are trying to execute that jar file from outside maven with some java command line or another.
When Maven calls Java to compile your code, it's adding all your dependencies to the classpath.
When you are running your code, you aren't.
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>
回答2:
Seems like you have not included the javax.ws.rs.jar
file in your class path.
Download Link
来源:https://stackoverflow.com/questions/27390114/java-lang-noclassdeffounderror-for-maven