2013-03-28 7 views
9

コンソールアプリケーションを作成しています。私はjarファイルの外側にあるconfフォルダ内の設定ファイルを持ち、このフォルダを自分のアプリケーションのクラスパスとして登録したいと考えています。maven-assembly-pluginでclasspathを設定できません

私はmvn assembly:singleコマンドを実行し、jarファイルを取得しますが、java -jar MyApplication.jarでこのJARを実行しようとすると、設定ファイルを読み取ることができません。

私は通常、MANIFESTクラスパスエントリではなく、この構成でのmaven-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

にこのスニペットを持っている:

<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を使用して、アセンブリ記述子の依存関係の宛先を一致させます。

視点

関連する問題