2017-03-17 4 views
0

私は、Javaプロジェクトを構築するためにmavenを使用しています。私のプロジェクトには多くの依存関係があります。今、私はこのプロジェクトをサーバーに展開する必要があるので、すべての依存関係を含む自己完結型の実行可能なjarファイルを作成したいと考えています。私はmaven shade pluginが推奨されていた古い質問に行きましたが、mavenでこれを行うことが可能かどうかは疑問です。 mavenを使用するだけで、自己完結型の実行可能なjarを作成する方法はありますか?Mavenを使用して自己完結型の実行可能なjarファイルを構築するにはどうすればよいですか?

ここ

答えて

1

のmavenで実行可能なJARを構築する方法を説明リンク:私は何が必要だと思う

https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html

+0

これもシェードプラグインを使用しています。ちょうどMavenでこれを行う方法はありますか? – enitihas

+1

Mavenはプラグインで動作し、シェードで実行可能なJARを作成できます。陰影を使用してみてください。問題がある場合は、 – Kikou

+1

を送信してください。私は陰影のプラグインを試してみます。 – enitihas

1

は、脂肪のjarまたは単一jarファイルです。あなたのPOMファイルに以下を追加し、変更 属性

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 

     <!-- Skip the tests run. --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.15</version> 
      <configuration> 
       <skipTests>true</skipTests> 
      </configuration> 
     </plugin> 

     <!-- Sources generation --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-source-plugin</artifactId> 
      <version>2.4</version> 
      <executions> 
       <execution> 
        <id>attach-sources</id> 
        <phase>verify</phase> 
        <goals> 
         <goal>jar-no-fork</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>3.0.0</version> 
      <configuration> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <archive> 
        <manifest> 
         <mainClass>**********Put main class here********</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> <!-- this is used for inheritance merges --> 
        <phase>package</phase> <!-- bind to the packaging phase --> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

使用MVNパッケージをいつものようにjarファイルを構築します。

0

その他は、すでに答えているが、ここであなたは今でjarファイルを実行することができます例の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.greg</groupId> 
    <artifactId>blackbox-tester</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>blackbox-tester</name> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpclient</artifactId> 
      <version>4.5.3</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpcore</artifactId> 
      <version>4.4.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>1.3.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-lang3</artifactId> 
      <version>3.5</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>3.0.0</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <transformers> 
           <transformer 
             implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <manifestEntries> 
             <Main-Class>com.greg.blackboxtester.Application</Main-Class> 
            </manifestEntries> 
           </transformer> 
          </transformers> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </build> 

</project> 

です:

のjava -jarターゲット/ブラックボックステスター-1.0-SNAPSHOT.jarに

関連する問題