WEB的mavan项目构建生成可执行jar包

构建可执行war包文档(tomcat7-maven-plugin):

  • JDK 1.7+ 
  • Maven 3.0 or later 
  •  tomcat7-maven-plugin version 2.1/2.0/2.0-beta-1


0、环境要求

  • Unix System\windwos\macOS
  • JDK 1.7+ 
  • Maven 3.0 or later 
  •  我测试的编译环境是:
  • macOS10.11.6和windows10
  • jdk1.8/jdk1.7
  • Maven 3.3.9 
  • 我的本机开发环境: 
  • MacOS 10.11.6
  • eclipse Mars.2 


1、在pom中配置tomcat7-maven-plugin

<project>
  ...
  <packaging>war</packaging>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <path>demo</path>
              <!-- optional, needed only if you want to use a preconfigured server.xml file -->
              <serverXml>src/main/tomcatconf/server.xml</serverXml>
              <!-- optional values which can be configurable -->
              <attachArtifactClassifier>default value is exec-war but you can customize</attachArtifactClassifier>
              <attachArtifactClassifierType>default value is jar</attachArtifactClassifierType>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

2、执行构建生成jar包

执行man  clean install

会在target下生成相应的jar包

如果想要修改jar包名称,可以在 < configuration >标签中定义<finalName>标签修改生成的jar包名称



3、执行构建出来的jar包部署应用
    
    

执行构建出来的jar包:

  java -jar yourjar

其他参数:

usage: java -jar [path to your exec war jar]
 -ajpPort <ajpPort>                     ajp port to use
 -clientAuth                            enable client authentication for
                                        https
 -D <arg>                               key=value
 -extractDirectory <extractDirectory>   path to extract war content,
                                        default value: .extract
 -h,--help                              help
 -httpPort <httpPort>                   http port to use
 -httpProtocol <httpProtocol>           http protocol to use: HTTP/1.1 or
                                        org.apache.coyote.http11.Http11Nio
                                        Protocol
 -httpsPort <httpsPort>                 https port to use
 -keyAlias <keyAlias>                   alias from keystore for ssl
 -loggerName <loggerName>               logger to use: slf4j to use slf4j
                                        bridge on top of jul
 -obfuscate <password>                  obfuscate the password and exit
 -resetExtract                          clean previous extract directory
 -serverXmlPath <serverXmlPath>         server.xml to use, optional
 -X,--debug                             debug

 
   
例如:如果需要改变启动容器的端口号(默认为8080)

  java -jar yourjar -httpPort 8081

 PS: 在测试过程中使用到的插件版本如下:
2.0、2.0-beta-1、2.1、2.2

都可以正常构建生成jar包,但是在执行启动jar包的过程中,在jdk1.8的环境下:
  • 2.1的版本正常,可以正常执行部署,启动运行
  • 2.0和2.0-beta-1版本可以正常部署,但是启动tomcat访问中报java.io异常,和jdk执行版本有关,经过多次测试,更换为jdk1.7执行没有可以正常使用。
  • 在jdk1.8环境和jdk1.7环境下2.2版本都存在不可以正常创建webapp文件夹,也不可以将应用部署到webapp中,如果手动将jar包的相关内容部署进.extract/再次执行启动命令可以正常使用
综上:可以使用2.1版本的插件。 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值