IntelliJ IDEA自身とMavenプロジェクトをパッケージ化しています

1.アイデア自体の包装

1.1成果物を作成します

  プロジェクト構造プロジェクトを開くためのショートカットキー(Ctrlキー+ Altキー+ Shiftキー+ S)。作成されたアーティファクト

  

   次に、以下のように、メインクラスを指定:

  

   最後に、成果物を作成ゲット

   

1.2包装アーティファクト

  メニューバーのオプションのビルドでは、最後の列アーティファクトを構築

  

  最後に、表示されたウィンドウを作成

  

   パックの結果を取得します。

  

2. Mavenの道パッケージ

2.1瓶のない第三者に依存のmaven-jarファイル・プラグインパッケージ

   次のようにのpom.xml構成は次のとおりです。

<! - ①他のjarパッケージに依存しません - >
    <ビルド>
        <資源>
            <資源>
                <TARGETPATH> $ {project.build.directory} /クラス</ TARGETPATH>
                <ディレクトリ>のsrc /メイン/リソース</ディレクトリ>
                <フィルタ>  </フィルタリング>
                <含まれます>
                    <include>の** / * .xmlの</ include>の
                    <include>の* * / * .confを</ include>の
                </includes>
            </resource>
        </resources>

        <plugins>
            <!--scala打包插件-->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--java打包插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.swordfall.restserver.base.WebServer</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

  运行:先mvn clean,再 package,在target中找到打包出来的xxx.jar包,运行java -jar xxx.jar即可,但是如果程序有依赖其他包,比如程序依赖jdbc去查询db,这时候再执行就会出现找不到jdbc依赖,因为我们并没有将依赖包打进去。

2.2 maven-assembly-plugins 解决依赖第三方jar包,并可执行jar的打包

  pom.xml配置如下:

<!--②解决依赖第三方,可执行jar的打包,全量打包-->
    <build>
        <resources>
            <resource>
                <targetPath>${project.build.directory}/classes</targetPath>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.conf</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <!--scala打包插件-->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--java打包插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.swordfall.restserver.base.WebServer</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

2.3 maven-assembly-plugins 解决依赖第三方jar包,并可执行jar的打包

总结

【参考资料】

https://blog.csdn.net/qq_16055765/article/details/79481258

https://www.cnblogs.com/Andrew520/p/8857603.html

https://blog.csdn.net/zzm3280/article/details/84953070

https://blog.csdn.net/hxpjava1/article/details/79711710

https://blog.csdn.net/u012834750/article/details/80937747 scala打包插件配置①

https://blog.csdn.net/tf461991046/article/details/80834685 scala打包插件配置②

https://blog.csdn.net/u013019338/article/details/83377070 spring-boot配置读取外部配置文件

https://www.cnblogs.com/hdwang/p/6627912.html 普通jar包如何读取外部的配置文件

https://www.cnblogs.com/wangfajun/p/9585530.html linux shell脚本启动或停止jar

https://blog.csdn.net/qq_18300109/article/details/80798334 IDEA如何打包可运行jar,外部引用jar包版

https://blog.csdn.net/qingfengmuzhu1993/article/details/80284739 IDEA自身打包方式

https://my.oschina.net/u/2377110/blog/1585553 shade 过滤包名

 

おすすめ

転載: www.cnblogs.com/swordfall/p/11359370.html