läuft standalone ausführbare java-Datei in eclipse-Ergebnisse in NoClassDefFound
Hallo, ich habe ein basic-Jersey-Client, dass ich versuche, ausgeführt mit einer main()
in meinem "main" java-Klasse. Kompiliert er fein in Eclipse, aber wenn ich versuche, führen Sie es als java-Anwendung habe ich bekommen:
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
Kann mir jemand sagen was ich falsch mache? Hier ist meine pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ca.ubc.iamwsClient</groupId>
<artifactId>iamwsClient</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>iamwsClient</name>
<properties>
<jersey.version>2.5.1</jersey.version>
<target.dir>target</target.dir>
<project.build.directory>target</project.build.directory>
</properties>
<repositories>
<repository>
<id>JBoss Repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<!-- jackson dependencies for pojo/json support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-processing</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- end jackson deps -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId>
<version>1.8</version> </dependency> -->
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<!-- <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId>
<version>1.1</version> </dependency> -->
</dependencies>
<build>
<finalName>iamwsClient</finalName>
<outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>ca.ubc.iamwsClient.IamwsClient</mainClass>
</configuration>
</plugin> -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>ca.ubc.iamwsClient.IamwsClient</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.1,)
</versionRange>
<goals>
<goal>
copy-dependencies
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Client, die ich versuche zu laufen:
package ca.ubc.iamwsClient;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.jackson.JacksonFeature;
import ca.ubc.iamwsClient.json.CreateEmployeeBean;
import ca.ubc.iamwsClient.json.CreateEmployeeResponseBean;
/**
* Main class.
*
*/
public class IamwsClient {
private WebTarget getTarget(String targetUrl) throws Exception {
//create the client
Client c = ClientBuilder.newClient().register(JacksonFeature.class);
return c.target(targetUrl);
}
public CreateEmployeeResponseBean sendCreateEmployeeRequest(CreateEmployeeBean createBean, String url) {
CreateEmployeeResponseBean rb = null;
try {
WebTarget target = getTarget(url);
WebTarget wt = target.path("employeeAutoCreate");
WebTarget generateTarget = wt.path("generate");
rb = generateTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(createBean,MediaType.APPLICATION_FORM_URLENCODED_TYPE),
CreateEmployeeResponseBean.class);
System.out.println("CreateEmployee: generate response: success=" + rb.getSuccess() + " message=" + rb.getMessage());
} catch (Throwable t) {
t.printStackTrace();
System.out.println("*********EXCEPTION THROWN: " + t.getMessage());
}
return rb;
}
public static void main(String[] args) {
String testUrl="http://localhost:9090/iamws";
CreateEmployeeBean bean = new CreateEmployeeBean();
//... set some details on bean....
IamwsClient client = new IamwsClient();
CreateEmployeeResponseBean response = client.sendCreateEmployeeRequest(bean, testUrl);
if (response != null) {
System.out.println("*********server responded with flag: " + response.getSuccess() + " message: " + response.getMessage());
}
}
}
- Bitte schauen Sie das; stackoverflow.com/questions/17366266/...
- Ich Tat dies sehen - aber es gilt nicht für mich. Mein problem denke ich ist, dass die Abhängigkeiten nicht verfügbar sind, um die runtime-Konfiguration von eclipse. Ich bin gerade ausgeführt werden, das als ein standalone-java-app. Wie bekomme ich eclipse, um die Abhängigkeiten? Ich dachte, dass meine pom bedeckt es. (Ich bin nicht mit restEasy)
- Ich hatte ein solches Problem vor, wenn ich jersey verwendet 2.18 mit jdk1.6. Aber was ich gefunden habe ist, dass jersey 2.6 ist die Letzte version, die unterstützt jdk1.6.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Müssen Sie sicherstellen, dass die JAR-Abhängigkeit mit
org.glassfish.jersey.client.JerseyClientBuilder
- Klasse zur Verfügung, die auf Ihre Anwendung classpath während der Laufzeit. Es gibt wirklich keine andere Erklärung zuNoClassDefFound
Fehler.Aus dem, was ich von google auf diese Klasse, es sollte in
In anderen Worten: Ihr
com.sun.jersey
Abhängigkeit möglicherweise fehlt es.BEARBEITEN
Dies ist die eigentliche Antwort, die dem OP Hinzugefügt, um die Frage danach:
Hatte er schon
org.glassfish.jersey.core
undorg.glassfish.jersey.connectors
. Er entferntcom.sun.jersey
Abhängigkeit.Werde ich versuchen, es selbst zu kurz.
java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)
- ich bin nur dieses laufen als standalone-java-client, also sollte ich nicht angeben müssen java-ee-ich glaube nicht, dass?jersey-client
Abhängigkeit