2013-03-28 15 views
9

我正在创建控制台应用程序。我想在conf文件夹中的jar文件之外拥有配置文件,并且希望将该文件夹注册为我的应用程序的类路径。无法使用maven-assembly-plugin设置类路径

我运行了mvn assembly:single命令,得到一个jar文件,但是当我试图运行这个JAR与java -jar MyApplication.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> 
+0

是我的错,我只好把 –

回答

8

是我的错,我只好把

<Class-Path>./conf/</Class-Path> 

,而不是

<Class-Path>.conf/</Class-Path> 
2

我平时不使用的组件插件生成的清单类路径条目,但此配置,而行家-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> 

我只使用程序集插件将依赖关系(包括可传递的依赖项)复制到我的构建目录中,并创建分发档案。你也可以使用依赖插件来做到这一点。 如果您想将您的依赖关系复制到分发树的子目录中,请使用maven-jar-plugin配置中的classpathPrefix来匹配您的程序集描述符依赖项目标。

方面