我已经使用maven构建了一个jar并且构建成功了。
当我尝试使用java -jar
运行此jar时,java.lang.NoClassDefFoundError异常即将发生,因为所有maven依赖项jar在classpath中都不可用。
我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pdss-loadTesting</groupId>
<artifactId>load-testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pdss_load_testing</name>
<description>load test pdss</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>dependency/</classpathPrefix>
<mainClass>loadtesting.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>generate-java-slice</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<exec executable="mkdir">
<arg value="-p" />
<arg value="target/generated-sources" />
</exec>
<exec executable="git">
<arg value="submodule" />
<arg value="init" />
</exec>
<exec executable="git">
<arg value="submodule" />
<arg value="update" />
</exec>
<exec executable="git">
<arg value="submodule" />
<arg value="foreach" />
<arg value="git" />
<arg value="checkout" />
<arg value="master" />
</exec>
<exec executable="git">
<arg value="submodule" />
<arg value="foreach" />
<arg value="git" />
<arg value="pull" />
<arg value="origin" />
<arg value="master" />
</exec>
<exec executable="slice2java">
<arg value="-I/usr/share/Ice-3.4.2/slice" />
<arg value="submodules/slice/asr/asr.ice" />
<arg value="submodules/slice/pds/pds.ice" />
<arg value="--underscore" />
<arg value="--output-dir" />
<arg value="target/generated-sources" />
</exec>
</tasks>
</configuration>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/extracted</outputDirectory>
<includeTypes>zip</includeTypes>
<includeClassifiers>include</includeClassifiers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<!--version>2.3.1</version> <configuration> <source>1.5</source> <target>1.5</target>
</configuration -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!--plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version> <configuration> <show>private</show> <nohelp>true</nohelp>
</configuration> <executions> <execution> <id>attach-javadocs</id> <goals>
<goal>jar</goal> </goals> </execution> </executions> </plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.4</version>
<configuration>
<finalName>${project.name}-${project.version}</finalName>
<archive>
<manifest>
<mainClass>
com.samsung.sec.svoice.asr.dash.DashAsrWrapper</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>assembly-jar-with-dependencies.xml</descriptor>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</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-antrun-plugin
</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>
generate-sources
</goal>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.1,)
</versionRange>
<goals>
<goal>
unpack-dependencies
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
aspectj-maven-plugin
</artifactId>
<versionRange>
[1.3,)
</versionRange>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.sonatype.haven.HavenCli</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<!-- add dependencies -->
<dependencies>
<!-- dependency> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId>
<version>2.1.5</version> </dependency -->
<!-- dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId>
<version>1.9.5</version> </dependency -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!--dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId>
<version>4.2.3</version> </dependency -->
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<!--dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId>
<version>1.7.2</version> </dependency -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
<!--dependency> <groupId>Ice</groupId> <artifactId>zeroc-ice</artifactId>
<version>3.4.2</version> </dependency -->
<dependency>
<groupId>com.zeroc</groupId>
<artifactId>ice</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
<dependency>
<groupId>com.samsung.svoice</groupId>
<artifactId>registry-framework</artifactId>
<version>0.2.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.12.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
<version>0.9.16</version>
</dependency>
<dependency>
<groupId>commons-jexl</groupId>
<artifactId>commons-jexl</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
</dependency>
<dependency>
<groupId>com.samsung.svoice</groupId>
<artifactId>pdss_prashant</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>Ice</groupId>
<artifactId>zeroc-ice</artifactId>
<version>3.4.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/Ice.jar</systemPath>
</dependency>
</dependencies>
<distributionManagement>
<!-- Publish the releases here -->
<repository>
<id>dcog</id>
<url>https://maven.samsungcloud.org/nexus/content/repositories/dcog
</url>
</repository>
<!-- Publish snapshots here -->
<snapshotRepository>
<id>dcog-snapshots</id>
<url>https://maven.samsungcloud.org/nexus/content/repositories/dcog-snapshots
</url>
</snapshotRepository>
</distributionManagement>
<!-- download artifacts from this repo -->
<repositories>
<repository>
<id>public</id>
<url>https://maven.samsungcloud.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>svoice</id>
<url>https://maven.samsungcloud.org/nexus/content/repositories/svoice/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>svoice-snapshots</id>
<url>https://maven.samsungcloud.org/nexus/content/repositories/svoice-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!--repository> <id>sonatype</id> <name>Sonatype Groups</name> <url>https://oss.sonatype.org/content/groups/public</url>
</repository -->
</repositories>
<!-- download plugins from this repo -->
<pluginRepositories>
<pluginRepository>
<id>public</id>
<url>https://maven.samsungcloud.org/nexus/content/groups/public/
</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>