maven 把工程大包成可执行jar包,pom配置

来源:互联网 发布:绿联mac网线usb驱动 编辑:程序博客网 时间:2024/04/28 07:30


任务:将maven构建的工程打成jar包,并使用脚本做定时任务

1.首先将maven搭建的工程打成jar


最近在做一个Spring boot的工程,需要打成可执行jar包,使用java -jar XXX.jar,由于在默认情况下,maven在做mvn pakage时,只是将项目编译打包到一个jar中,其他的类库则需要引用才行。
需要在将该工程所支持的类库打在一个包中

在pom.xml中加入以下插件

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>com.App</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>assembly</goal>
            </goals>
        </execution>
    </executions>
</plugin>


上述代码中在<mainClass></mainClass>填写程序的入口类,含main方法的类

2.编辑完后执行

mvn assembly:assembly

在target目录下会生成   *.jar 文件


3.运行jar文件

java -jar *.jar


然后出错:
 No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
查了查错误:修改了一下pom配置
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <mainClass>com.App</mainClass>
                </configuration>
                  <executions>
                    <execution>
                      <goals>
                        <goal>repackage</goal>
                      </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
              <artifactId>maven-assembly-plugin</artifactId>
              <version>2.2-beta-5</version>
              <configuration>
                <archive>
                  <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>com.APP</mainClass>
                  </manifest>
                </archive>
                <descriptorRefs>
                  <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
              </configuration>
              <executions>
                <execution>
                  <id>assemble-all</id>
                  <phase>package</phase>
                  <goals>
                    <goal>single</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
        </plugins>
    </build>


然后执行mvn clean 
在执行 mvn package
打包:XXX.jar

然后执行java -jar  XXX.jar
成功启动:
[main] [com.App] [INFO] - Started App in 20.268 seconds (JVM running for 21.389)

通过谷歌,火狐访问地址报错:错误代码:ERR_UNSAFE_PORT
原因是我的端口是6666,谷歌认定为不安全端口,限制访问导致。

一下是谷歌官方列出的非安全端口

1,    // tcpmux
  7,    // echo
  9,    // discard
  11,   // systat
  13,   // daytime
  15,   // netstat
  17,   // qotd
  19,   // chargen
  20,   // ftp data
  21,   // ftp access
  22,   // ssh
  23,   // telnet
  25,   // smtp
  37,   // time
  42,   // name
  43,   // nicname
  53,   // domain
  77,   // priv-rjs
  79,   // finger
  87,   // ttylink
  95,   // supdup
  101,  // hostriame
  102,  // iso-tsap
  103,  // gppitnp
  104,  // acr-nema
  109,  // pop2
  110,  // pop3
  111,  // sunrpc
  113,  // auth
  115,  // sftp
  117,  // uucp-path
  119,  // nntp
  123,  // NTP
  135,  // loc-srv /epmap
  139,  // netbios
  143,  // imap2
  179,  // BGP
  389,  // ldap
  465,  // smtp+ssl
  512,  // print / exec
  513,  // login
  514,  // shell
  515,  // printer
  526,  // tempo
  530,  // courier
  531,  // chat
  532,  // netnews
  540,  // uucp
  556,  // remotefs
  563,  // nntp+ssl
  587,  // stmp?
  601,  // ??
  636,  // ldap+ssl
  993,  // ldap+ssl
  995,  // pop3+ssl
  2049, // nfs
  3659, // apple-sasl / PasswordServer
  4045, // lockd
  6000, // X11
  6665, // Alternate IRC [Apple addition]
  6666, // Alternate IRC [Apple addition]
  6667, // Standard IRC [Apple addition]
  6668, // Alternate IRC [Apple addition]
  6669, // Alternate IRC [Apple addition]










原创粉丝点击