问题描述
- 内嵌jetty可执行war包问题求助
-
最近写了一个简单的应用,其中需要几个页面,所以使用了jsp+springMVC,服务器使用了jetty,内嵌的方式,
写了一个Java类启动,在eclipse中开发测试的时候没有问题,只要运行启动类,jetty就启动了,可以访问页面。但是,
当开发完成,我想打成一个可执行的war包,使用java -jar XXX.war命令运行的时候,在启动时报如下错误:C:workspaceCCERTooltarget>java -Xms512m -Xmx512m -XX:MaxPermSize=96m -jar CCE RTool-0.0.1.war& Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=96m; support was removed in 8.0 2016-05-20 09:46:22.235:INFO::main: Logging initialized @245ms war file path:file:/C:/workspace/CCERTool/target/CCERTool-0.0.1.war 2016-05-20 09:46:22.296:INFO:oejs.Server:main: jetty-9.2.z-SNAPSHOT 2016-05-20 09:46:27.905:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@50cbc42f{/,file:/C:/workspace/CCERTool/target/CCERTool-0.0 .1/,STARTING}{file:/C:/workspace/CCERTool/target/CCERTool-0.0.1.war} …….. at org.eclipse.jetty.server.Server.doStart(Server.java:354) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLife Cycle.java:68) at com.thomsonreuters.ccertool.Launcher.startJetty(Launcher.java:83) at com.thomsonreuters.ccertool.Launcher.main(Launcher.java:94) Caused by: java.lang.NoClassDefFoundError: org/apache/jasper/servlet/JspServlet at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoade
我的打包过程如下:
1.pom.xml中相关依赖
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>9.2.13.v20150730</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version>9.2.13.v20150730</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-jsp</artifactId> <version>9.2.13.v20150730</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.23</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.6.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.6.0</version> </dependency> <!-- 使用jstp --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>provided</scope> </dependency>
- pom.xml中打包相关配置
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <archive> <manifest> <mainClass>com.thomsonreuters.ccertool.Launcher</mainClass> <!-- <addClasspath>true</addClasspath> --> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>main-class-placement</id> <phase>prepare-package</phase> <configuration> <target> <move todir="${project.build.directory}/${project.artifactId}-${project.version}/"> <fileset dir="${project.build.directory}/classes/"> <include name="**/*/Launcher.class" /> </fileset> </move> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.5.1</version> <executions> <execution> <id>jetty-classpath</id> <phase>prepare-package</phase> <goals> <goal>unpack-dependencies</goal> </goals> <configuration> <includeGroupIds>org.eclipse.jetty,javax.servlet</includeGroupIds> <excludes>META-INF/ECLIPSEF.SF,META-INF/ECLIPSEF.RSA,META-INF/eclipse.inf</excludes> <outputDirectory> ${project.build.directory}/${project.artifactId}-${project.version} </outputDirectory> </configuration> </execution> </executions> </plugin> <!-- to support compilation in linux --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <target>1.7</target> <source>1.7</source> <encoding>UTF-8</encoding> </configuration> </plugin>
3.war包的结构
其中,com下面是我的启动类Launcher.class, org下面和javax下面应该是jetty依赖的相关包,我看了下面确实没有org/apache/jasper/servlet/JspServlet, 那么要怎样才能打包的时候打到war包的根目录下呢?如果是jetty的依赖应该在maven-dependency-plugin这个阶段打到war里面吧?
求有经验的同学指点,万分感谢!
时间: 2024-10-26 07:44:13