• maven 项目打可执行jar包


    昨晚,突然就来了紧急任务。
    验签较慢,着手优化,发来一个demo。
     
     
    首先需要把该demo部署在Linux上。
     
     
    该项目是maven 项目,所以用maven打个jar包,打完jar包之后,可在Linux上直接执行 java -jar XXXX.jar
     
    所以在pom.xml文件中添加
              <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <!-- 此处指定main方法入口的class -->
                                <mainClass>test.SignTestMain</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>assembly</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    这段代码就好了。
     
    注意:这是添加在<build>和<plugins>里面的,完整的如下。
         <build>
                <plugins>
                      <plugin>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                                  <source>1.6</source>
                                  <target>1.6</target>
                                  <encoding>UTF-8</encoding>
                            </configuration>
                      </plugin>
                      <!-- <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-jar-plugin</artifactId>
                            <configuration>
                                  <source>1.8</source>
                                  <target>1.8</target>
                                  <archive>
                                        <manifest>
                                                         <mainClass>test.SignTestMain</mainClass>
                                        </manifest>
                                  </archive>
                                  <classesDirectory>
                                  </classesDirectory>
                            </configuration>
                      </plugin> -->
                       <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <!-- 此处指定main方法入口的class -->
                                <mainClass>test.SignTestMain</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>assembly</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                </plugins>
          </build>
    被注释掉的也是打jar包的一种方式,但是你采用这种方式你maven项目所依赖的jar不会被打进去,所以不合适。
  • 相关阅读:
    9.类与对象二----重载、值传递、可变个数形参
    1.数据库相关概念
    8.类与对象一举例
    7.类与对象一
    Educational Codeforces Round 91 (Rated for Div. 2) B. Universal Solution(思维)
    VS Code配置C++环境: Unable to start debugging. Unexpected GDB output from command报错
    Codeforces Round #655 (Div. 2) C. Omkar and Baseball(思维)
    Redis高可用,高性能,高并发
    .Net Core 中GC的工作原理
    大数据环境下该如何优雅地设计数据分层
  • 原文地址:https://www.cnblogs.com/yidiandhappy/p/7566962.html
Copyright © 2020-2023  润新知