Spring-Boot1.4.0项目部署问题小记

使用最新版的Spring-Boot1.4.0开发完项目后,部署到Linux机器上,其JDK版本是JDK7,启动报错:
org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0

由于在spring-boot的pom文件里面使用了jetty依赖:
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
            <scope>provided</scope>
        </dependency>


默认最新的会使用jetty的版本是9.3.11.v20160721,而jetty自从9.3.0开始必须要求使用 JDK8才行,所以项目启动不成功,当然在我自己的windows开发机上是可以启动的,因为我本地的JDK也是8的版本,尝试在spring-boot中降低其依赖jetty的版本,但是没成功,貌似其父parent,在IDEA的maven依赖中,看到jetty版本已经降了,但是打包后,依旧是最新的jetty,比较郁闷,所以就放弃了内嵌的jetty容器,以后有空再研究下原因,暂时采用了spring boot默认web内嵌的tomcat:
<!-- 默认会引入tomcat作为内嵌容器 -->
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

最新的tomcat,兼容JDK7,更改完毕后,启动项目又报错了,由于引入的config版本有点高, 所以就降到1.2.1了,介绍下config,非常不错的一个开源的解析properties,json文件的小神器工具包
<dependency>
            <groupId>com.typesafe</groupId>
            <artifactId>config</artifactId>
            <version>1.2.1</version>
            <!-- <version>1.3.0</version> 需要JDK8支持 -->
        </dependency>

最后再记录下,使用maven-assemble插件打包没生效的问题,注意

(1)src/main/bin写相对路径即可,打包时会自动拷贝上项目根目录

(2)斜杠不要写反,src\main\bin 在linux上是不会生效的


<?xml version="1.0"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <!--项目标识,设置的话,生成后的zip文件会加上此后缀-->
    <id></id>
    <!--打包格式-->
    <formats>
        <format>tar.gz</format>
    </formats>
    <!--是否包含根目录文件夹-->
    <includeBaseDirectory>true</includeBaseDirectory>

    <fileSets>

        <!--自定义文件描述集-->
        <fileSet>
            <!--自定义脚本目录打包-->
            <directory>src/main/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <includes>
                <include>*.*</include>
            </includes>
            <!--设置权限-->
            <fileMode>0755</fileMode>
        </fileSet>

        <fileSet>
        <!--外部配置文件打包-->
        <directory>src/main/config</directory>
        <outputDirectory>config</outputDirectory>
        <includes>
        <include>*.*</include>
        </includes>
        <fileMode>0755</fileMode>
        </fileSet>


    </fileSets>

    <dependencySets>

        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <!-- 将scope为runtime的依赖包打包到lib目录下。 -->
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>




 </assembly>


最后,备忘下启动任务的脚本:

root=`pwd`
echo $root

#exit
cs=`echo $root/lib/*jar | sed 's/ /:/g'`
#配置文件的目录,结尾必须加冒号,否则不识别
conf=":$root/config:"
#追加进入cp中
cs=$cs$conf
#打印
echo $cs
#执行
nohup java -cp  $cs  com.search.bigdata.ApplicationMain   &>/dev/null  &   echo $! >pid&



有什么问题可以扫码关注微信公众号:我是攻城师(woshigcs),在后台留言咨询。
技术债不能欠,健康债更不能欠, 求道之路,与君同行。

猜你喜欢

转载自qindongliang.iteye.com/blog/2320413