2017-05-12 20 views
1

これはダム(私を案内してください)かもしれませんが、Mavenを使用しているパッケージに依存関係のバイナリをいくつか含めることを試みています。ビルドされたjarに(ビルド中に)ビルドされたファイルを含めるには?

依存関係はjinputであり、ビルド中にバイナリが "展開され"ます。バイナリはビルド後に解凍されるので、ファイルをインクルードする標準的な "リソース"を使ってバイナリを自分の.jarに含めません。ビルド時にパッケージが存在しない場合、Mavenにバイナリをパッケージに含めるにはどうしたらいいですか?

<?xml version="1.0" encoding="UTF-8"?> 
<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.mycompany</groupId> 
    <artifactId>ProjectA</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <maven.compiler.source>1.8</maven.compiler.source> 
     <maven.compiler.target>1.8</maven.compiler.target> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>net.java.jinput</groupId> 
      <artifactId>jinput</artifactId> 
      <version>2.0.7</version> 
     </dependency> 
    </dependencies> 


    <build> 
     <plugins> 
      <!-- Unpack the jinput binaries to "bin" --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.8</version> 
       <executions> 
        <execution> 
         <id>unpack jinput windows</id> 
         <phase>compile</phase> 
         <goals> 
          <goal>unpack</goal> 
         </goals> 
         <configuration> 
          <skip>false</skip> 
          <artifactItems> 
           <artifactItem> 
            <groupId>net.java.jinput</groupId> 
            <artifactId>jinput-platform</artifactId> 
            <version>2.0.7</version> 
            <classifier>natives-windows</classifier> 
            <type>jar</type> 
            <overWrite>true</overWrite> 
            <outputDirectory>/bin</outputDirectory> 
            <includes>**/*.dll</includes> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 

     <resources> 
      <resource> 
       <directory>${project.builddir}</directory> 
       <includes> 
        <include>bin/*.dll</include> 
       </includes> 
      </resource> 
     </resources> 
    </build> 
</project> 

答えて

1

リソースの代わりに、maven-jar-pluginを使用できます。

以下のコードをテストしても問題ありません。あなたのPOMファイルは上記のコードを変更したら

<properties> 
    <my.dll.folder>${project.build.directory}/unpackedfiles</my.dll.folder> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>net.java.jinput</groupId> 
     <artifactId>jinput</artifactId> 
     <version>2.0.7</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>3.0.0</version> 
      <executions> 
       <execution> 
        <id>unpack</id> 
        <phase>package</phase> 
        <goals> 
         <goal>unpack</goal> 
        </goals> 
        <configuration> 
         <artifactItems> 
          <artifactItem> 
           <groupId>net.java.jinput</groupId> 
           <artifactId>jinput-platform</artifactId> 
           <version>2.0.7</version> 
           <classifier>natives-windows</classifier> 
           <type>jar</type> 
           <overWrite>false</overWrite> 
           <outputDirectory>${my.dll.folder}/bin</outputDirectory> 
           <destFileName>optional-new-name.jar</destFileName> 
           <includes>**/*.dll</includes> 
          </artifactItem> 
         </artifactItems> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.4</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>jar</goal> 
        </goals> 
        <configuration> 
         <classesDirectory>${my.dll.folder}</classesDirectory> 
         <classifier>sample</classifier> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

、あなたは、あなたがたjarファイルがbinフォルダ内の必要な* .dllファイルが含まれていることを確認することができますコマンド

mvn clean package 

の下に実行することができます。

同じ出力jarファイルを上書きする場合は、<classifier>タグを削除できます。

関連する問題