之前项目部署一直是tomcat,后来项目需要使用jetty,刚开始部署,遇到很多问题,记录一下,有同样问题的可以借鉴一下。
如何使用jetty:
1.pom.xml加入插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
</plugin>
</plugins>
</build>
2.run as -> run configurations -> goals: jetty:run
错误列表:
1.配置问题
[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (D:\Soft\maven\maven_repository), alimaven (http://maven.aliyun.com/nexus/content/groups/public/)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
解决办法:在maven的settings.xml中配置插件 <pluginGroup>org.mortbay.jetty</pluginGroup>
2.版本问题
[WARNING] Error injecting: org.eclipse.jetty.maven.plugin.JettyRunMojo
java.lang.TypeNotPresentException: Type org.eclipse.jetty.maven.plugin.JettyRunMojo not present
at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:115)
at org.eclipse.sisu.space.NamedClass.load(NamedClass.java:46)
at org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClass.java:48)
解决办法:jetty-maven-plugin的版本要与jdk一致,例如现在用的jdk1.6 配置如下:
排查过程中,主要就是这两个问题导致jetty启不来,解决后jetty正常启动。