Ich versuche, eine Serveranwendung in ein Maven-Projekt zu konvertieren und es als .jar mit Maven zu exportieren. Nachdem ich das Projekt in Eclipse importiert und es mit dem Maven-Plugin konvertiert habe, habe ich eine POM-Datei erhalten. Nach dem Ausführen des mvn-Pakets gab es viele Fehler, bei denen .jar-Bibliotheksabhängigkeiten innerhalb des Projekts beteiligt waren.NoClassDefFoundError Exportieren von .jar mit Maven
Ich habe diese Abhängigkeiten in POM hinzugefügt und ein Plugin hinzugefügt, das den Export einer ausführbaren JAR-Datei ermöglicht. Meine POM-Datei unter:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>160422_v3_Metadecoder</groupId>
<artifactId>160422_v3_Metadecoder</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.class.ws.classServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>gson-2.6.2</groupId>
<artifactId>gson-2.6.2</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\gson-2.6.2.jar</systemPath>
</dependency>
<dependency>
<groupId>classDecLib</groupId>
<artifactId>classDecLib</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\classDecLib.jar</systemPath>
</dependency>
<dependency>
<groupId>logging-interceptor-2.7.5</groupId>
<artifactId>logging-interceptor-2.7.5</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\logging-interceptor-2.7.5.jar</systemPath>
</dependency>
<dependency>
<groupId>javaClientAPI-1302</groupId>
<artifactId>javaClientAPI-1302</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\javaClientAPI-1302.jar</systemPath>
</dependency>
<dependency>
<groupId>javaClientAPI-2202</groupId>
<artifactId>javaClientAPI-2202</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\javaClientAPI-2202.jar</systemPath>
</dependency>
<dependency>
<groupId>joda-time-2.9.3</groupId>
<artifactId>joda-time-2.9.3</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\joda-time-2.9.3.jar</systemPath>
</dependency>
<dependency>
<groupId>okhttp-2.7.5</groupId>
<artifactId>okhttp-2.7.5</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\okhttp-2.7.5.jar</systemPath>
</dependency>
<dependency>
<groupId>swagger-annotations-1.5.9</groupId>
<artifactId>swagger-annotations-1.5.9</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\swagger-annotations-1.5.9.jar</systemPath>
</dependency>
<dependency>
<groupId>cdi-websocket-9.3.6.v20151106</groupId>
<artifactId>cdi-websocket-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\cdi-websocket-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>servlet-api-3.1</groupId>
<artifactId>servlet-api-3.1</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\servlet-api-3.1.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-xml-9.3.6.v20151106</groupId>
<artifactId>jetty-xml-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-xml-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-webapp-9.3.6.v20151106</groupId>
<artifactId>jetty-webapp-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-webapp-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-util-9.3.6.v20151106</groupId>
<artifactId>jetty-util-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-util-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-servlet-9.3.6.v20151106</groupId>
<artifactId>jetty-servlet-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-servlet-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-server-9.3.6.v20151106</groupId>
<artifactId>jetty-server-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-server-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-security-9.3.6.v20151106</groupId>
<artifactId>jetty-security-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-security-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-schemas-3.1</groupId>
<artifactId>jetty-schemas-3.1</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-schemas-3.1.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-rewrite-9.3.6.v20151106</groupId>
<artifactId>jetty-rewrite-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-rewrite-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-quickstart-9.3.6.v20151106</groupId>
<artifactId>jetty-quickstart-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-quickstart-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-proxy-9.3.6.v20151106</groupId>
<artifactId>jetty-proxy-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-proxy-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-plus-9.3.6.v20151106</groupId>
<artifactId>jetty-plus-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-plus-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-nosql-9.3.6.v20151106</groupId>
<artifactId>jetty-nosql-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-nosql-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-jndi-9.3.6.v20151106</groupId>
<artifactId>jetty-jndi-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-jndi-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-jmx-9.3.6.v20151106</groupId>
<artifactId>jetty-jmx-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-jmx-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-jaspi-9.3.6.v20151106</groupId>
<artifactId>jetty-jaspi-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-jaspi-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-jaas-9.3.6.v20151106</groupId>
<artifactId>jetty-jaas-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-jaas-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-io-9.3.6.v20151106</groupId>
<artifactId>jetty-io-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-io-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-infinispan-9.3.6.v20151106</groupId>
<artifactId>jetty-infinispan-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-infinispan-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-http-9.3.6.v20151106</groupId>
<artifactId>jetty-http-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-http-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-deploy-9.3.6.v20151106</groupId>
<artifactId>jetty-deploy-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-deploy-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-continuation-9.3.6.v20151106</groupId>
<artifactId>jetty-continuation-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-continuation-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-client-9.3.6.v20151106</groupId>
<artifactId>jetty-client-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-client-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-annotations-9.3.6.v20151106</groupId>
<artifactId>jetty-annotations-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-annotations-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>jetty-alpn-server-9.3.6.v20151106</groupId>
<artifactId>jetty-alpn-server-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\jetty-alpn-server-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>gcloud-session-manager-9.3.6.v20151106</groupId>
<artifactId>gcloud-session-manager-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\gcloud-session-manager-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>cdi-servlet-9.3.6.v20151106</groupId>
<artifactId>cdi-servlet-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\cdi-servlet-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>websocket-servlet-9.3.6.v20151106</groupId>
<artifactId>websocket-servlet-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\websocket-servlet-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>websocket-server-9.3.6.v20151106</groupId>
<artifactId>websocket-server-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\websocket-server-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>websocket-common-9.3.6.v20151106</groupId>
<artifactId>websocket-common-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\websocket-common-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>websocket-client-9.3.6.v20151106</groupId>
<artifactId>websocket-client-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\websocket-client-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>websocket-api-9.3.6.v20151106</groupId>
<artifactId>websocket-api-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\websocket-api-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>javax.websocket-api-1.0</groupId>
<artifactId>javax.websocket-api-1.0</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\javax.websocket-api-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>javax-websocket-server-impl-9.3.6.v20151106</groupId>
<artifactId>javax-websocket-server-impl-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\javax-websocket-server-impl-9.3.6.v20151106.jar</systemPath>
</dependency>
<dependency>
<groupId>javax-websocket-client-impl-9.3.6.v20151106</groupId>
<artifactId>javax-websocket-client-impl-9.3.6.v20151106</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}\lib\websocket\javax-websocket-client-impl-9.3.6.v20151106.jar</systemPath>
</dependency>
</dependencies>
</project>
Das Projekt baut richtig, aber die .jar, die folgenden Fehler gibt kommt heraus, wenn ich Java -jar example.jar:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
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: org.eclipse.jetty.server.Handler
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
Gibt es Tipps, was könnte dies verursachen würde sehr geschätzt werden.
edit: änderte ich mein Plugin dazu:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.class.ws.classServer</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
in einem Versuch, mit dem exportierte JAR alle jar Abhängigkeiten zu erhalten, aber diese die gleiche Ausgabe.
das ist, weil die JAR-Code nur enthält und keine der Abhängigkeiten. Sie müssen [Schatten] (https://maven.apache.org/plugins/maven-shade-plugin/) oder [assembly] (http://maven.apache.org/plugins/maven-assembly-plugin/) . – Seelenvirtuose
Das sieht vielversprechend aus .. Könnten Sie ein Beispiel geben, wie man das macht? Ist es nur ein Laufbefehl oder muss ich diese als Plugins zu meinem POM hinzufügen? Ich sehe Assembly-POM-Plugins, die ich brauche, um jede JAR-Datei anzugeben, die nicht verwaltet werden könnte. – Jaked222
Scheint albern, diese JARs aus deinem Projekt zu ziehen. Dafür sollte ein zentraler Maven Repo sein. Der springende Punkt sollte sein, Abhängigkeiten und Versionen außerhalb Ihrer Quelle zu verwalten. – duffymo