解决方案(长话短说):
pom.xml中缺少类路径,所以我需要添加这个条目(classpathPrefix):
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${dependencies.path}</classpathPrefix>
<mainClass>com.xafero.strangectrl.App</mainClass>
</manifest>
<manifestEntries>
<Class-Path>${dependencies.path}superloader-0.2.jar</Class-Path>
</manifestEntries>
</archive>
问题:
我正在使用m2eclipse使用命令构建我的项目: clean install package依赖项:copy-dependencies 。
问题是我希望将所有依赖关系jar放在文件夹 jars / 中。为了实现这个目的,我使用了 maven-dependency-plugin :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory> ${project.build.directory}/jars </outputDirectory>
</configuration>
</plugin>
我的实际问题是,当我运行我的jar时,无法解析所有依赖项,并且我 jars / 文件夹我有具有测试范围的库。
完整的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>com.xafero</groupId>
<artifactId>strangectrl</artifactId>
<version>1.1-alpha</version>
<packaging>jar</packaging>
<name>strangectrl</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>jinput</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>com.xafero</groupId>
<artifactId>superloader</artifactId>
<version>0.2</version>
<scope>system</scope>
<systemPath>${basedir}/lib_extra/superloader-0.2.jar</systemPath>
</dependency>
<dependency>
<groupId>xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.xafero.strangectrl.App</mainClass>
</manifest>
<manifestEntries>
<Class-Path>superloader-0.2.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/jars</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
@Jigar Joshi
我不确定这是你想要的,但这是我从eclipse的控制台输出(带-e)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.xafero:strangectrl:jar:1.1-alpha
[WARNING] 'dependencies.dependency.systemPath' for com.xafero:superloader:jar should not point at files within the project directory, ${basedir}/lib_extra/superloader-0.2.jar will be unresolvable by dependent projects @ line 28, column 16
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 74, column 12
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 82, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building strangectrl 1.1-alpha
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact xstream:xstream:jar:1.2.2 has been relocated to com.thoughtworks.xstream:xstream:jar:1.2.2
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ strangectrl ---
[INFO] Deleting C:\Users\MAG\git\StrangeCtrl\strangectrl\target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ strangectrl ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ strangectrl ---
[INFO] Compiling 33 source files to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ strangectrl ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\MAG\git\StrangeCtrl\strangectrl\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ strangectrl ---
[INFO] Compiling 9 source files to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ strangectrl ---
[INFO] Surefire report directory: C:\Users\MAG\git\StrangeCtrl\strangectrl\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.xafero.strangectrl.cmd.InputUtilsTest
Tests run: 17, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.527 sec
Running com.xafero.strangectrl.input.ControllerPollerTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.412 sec
Running com.xafero.strangectrl.input.SimpleCallbackTest
Tests run: 15, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.049 sec
Running pl.grzeslowski.strangectrl.cmd.CommandFactoryTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.057 sec
Running pl.grzeslowski.strangectrl.cmd.KeyCommandTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
Running pl.grzeslowski.strangectrl.cmd.MouseCommandTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
Running pl.grzeslowski.strangectrl.cmd.MouseMoveCommandTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec
Running pl.grzeslowski.strangectrl.cmd.PovDirectionTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
Running pl.grzeslowski.strangectrl.config.XStreamConfigLoaderTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.221 sec
Results :
Tests run: 62, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ strangectrl ---
[INFO] Building jar: C:\Users\MAG\git\StrangeCtrl\strangectrl\target\strangectrl-1.1-alpha.jar
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ strangectrl ---
[INFO] Installing C:\Users\MAG\git\StrangeCtrl\strangectrl\target\strangectrl-1.1-alpha.jar to C:\Users\MAG\.m2\repository\com\xafero\strangectrl\1.1-alpha\strangectrl-1.1-alpha.jar
[INFO] Installing C:\Users\MAG\git\StrangeCtrl\strangectrl\pom.xml to C:\Users\MAG\.m2\repository\com\xafero\strangectrl\1.1-alpha\strangectrl-1.1-alpha.pom
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ strangectrl ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ strangectrl ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ strangectrl ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\MAG\git\StrangeCtrl\strangectrl\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ strangectrl ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ strangectrl ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ strangectrl ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:copy-dependencies (default-cli) @ strangectrl ---
[INFO] Copying guava-15.0.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\guava-15.0.jar
[INFO] Copying xstream-1.2.2.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\xstream-1.2.2.jar
[INFO] Copying superloader-0.2.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\superloader-0.2.jar
[INFO] Copying junit-4.11.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\junit-4.11.jar
[INFO] Copying log4j-1.2.14.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\log4j-1.2.14.jar
[INFO] Copying jinput-2.0.5.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\jinput-2.0.5.jar
[INFO] Copying jinput-platform-2.0.5-natives-linux.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\jinput-platform-2.0.5-natives-linux.jar
[INFO] Copying jinput-platform-2.0.5-natives-osx.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\jinput-platform-2.0.5-natives-osx.jar
[INFO] Copying jinput-platform-2.0.5-natives-windows.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\jinput-platform-2.0.5-natives-windows.jar
[INFO] Copying jutils-1.0.0.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\jutils-1.0.0.jar
[INFO] Copying fest-assert-1.4.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\fest-assert-1.4.jar
[INFO] Copying fest-util-1.1.6.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\fest-util-1.1.6.jar
[INFO] Copying hamcrest-core-1.3.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\hamcrest-core-1.3.jar
[INFO] Copying mockito-all-1.9.0.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\mockito-all-1.9.0.jar
[INFO] Copying slf4j-api-1.5.8.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\slf4j-api-1.5.8.jar
[INFO] Copying slf4j-log4j12-1.5.8.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\slf4j-log4j12-1.5.8.jar
[INFO] Copying xpp3_min-1.1.3.4.O.jar to C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\xpp3_min-1.1.3.4.O.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.812s
[INFO] Finished at: Sun Jan 26 20:06:05 CET 2014
[INFO] Final Memory: 21M/173M
[INFO] ------------------------------------------------------------------------
答案 0 :(得分:1)
您正在通过
启动javajava -jar C:\Users\MAG\git\StrangeCtrl\strangectrl\target\strangectrl-1.1-alpha.jar
所以它在你的罐子里没有任何东西,如你所假设的那样,
您需要-cp C:\Users\MAG\git\StrangeCtrl\strangectrl\target\jars\*
设置