Java 无法使用maven程序集插件设置类路径
我正在创建控制台应用程序。我希望在Java 无法使用maven程序集插件设置类路径,java,maven-2,classpath,pom.xml,executable-jar,Java,Maven 2,Classpath,Pom.xml,Executable Jar,我正在创建控制台应用程序。我希望在conf文件夹中的jar文件之外有配置文件,并希望将此文件夹注册为我的应用程序的类路径 我运行mvn assembly:single命令,获取一个jar文件,但是当我尝试使用java-jar MyApplication.jar运行这个jar时,它无法读取配置文件 我在我的pom.xml <build> <finalName>MyApplication</finalName> <plugins>
conf
文件夹中的jar
文件之外有配置文件,并希望将此文件夹注册为我的应用程序的类路径
我运行mvn assembly:single
命令,获取一个jar文件,但是当我尝试使用java-jar MyApplication.jar
运行这个jar时,它无法读取配置文件
我在我的pom.xml
<build>
<finalName>MyApplication</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.7</version>
<configuration>
<projectNameTemplate>
[artifactId]-[version]
</projectNameTemplate>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
<manifest>
${basedir}/src/main/resources/META-INF/MANIFEST.MF
</manifest>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.my.test.App</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
我的申请
org.apache.maven.plugins
maven编译器插件
2.3.1
1.6
1.6
org.apache.maven.plugins
maven eclipse插件
2.7
[工件ID]-[版本]
真的
真的
2
${basedir}/src/main/resources/META-INF/MANIFEST.MF
maven汇编插件
带有依赖项的jar
假的
com.my.test.App
.conf/
我通常不使用汇编插件在清单中生成类路径条目,而是使用具有以下配置的maven jar插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<addExtensions>false</addExtensions>
<mainClass>com.my.test.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
org.apache.maven.plugins
maven jar插件
2.3.1
真的
真的
假的
com.my.test.App
我只使用汇编插件将依赖项(包括可传递的依赖项)复制到构建目录中,并创建分发存档。您也可以使用依赖插件来实现这一点。
如果要将依赖项复制到分发树的子目录中,请在maven jar插件配置中使用classpathPrefix来匹配程序集描述符依赖项目标
考虑到这是我的错误,我不得不
<Class-Path>./conf/</Class-Path>
/conf/
而不是
<Class-Path>.conf/</Class-Path>
.conf/
这是我的错误,我不得不