首先说下我tomcat和jdk版本,tomcat是(8.5.47、7.0.96)jdk是(1.8.0_40),tomcat我下了两个
1、我项目是maven项目,项目中用jetty启动服务,在eclispe中启动是正常的,但是放到tomcat下时就会包错,报错信息如下图:
2、粘出我pom文件如下
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yonyou.mes</groupId>
<artifactId>mes-ims</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>mes-ims-web</artifactId>
<packaging>war</packaging>
<name>mes</name>
<properties>
<!-- 主要依赖库的版本定义 -->
<me.modules.version>0.0.1-SNAPSHOT</me.modules.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jetty.version>9.2.21.v20170120</jetty.version>
</properties>
<dependencies>
<dependency>
<groupId>com.yonyou.mes</groupId>
<artifactId>mes-ims-core</artifactId>
<version>${me.modules.version}</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<!-- 插件配置 -->
<build>
<plugins>
<!-- compiler插件, 设定JDK版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!-- resource插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
<!-- war打包插件, 设定war包名称不带版本号 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<warName>ims</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- jar打包相关插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</plugin>
<!-- clean插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
</plugin>
<!-- install插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<contextXml>${project.basedir}/src/test/resources/jetty-context.xml</contextXml>
<webApp>
<contextPath>/${project.name}</contextPath>
<defaultsDescriptor>${project.basedir}/src/test/resources/webdefault.xml</defaultsDescriptor>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
</project>
3、因为是Jetty报错所以第一想到的就是去找jetty相关配置去,果然找到其中有依赖了Jetty的jar如下图:
4、maven项目用Jetty的时候用jetty插件就行了没必要去用依赖,所以注释掉这部分,然后我这将war包打包部署tomcat下成功启动。
5、为什么上面开始说tomcat和jdk版本呢,因为tomcat,jdk版本也有要求,由于上面问题是我一个同事出的问题,所以我这边解决以后就把pom文件发他,然而他那边还是报错,报错信息如下:
可以看到报错 信息就是版本不支持,所以我就让他jdk换成我这个版本,然后问题成功解决。