我想用Jetty9和Spring4进行一场可战战,并仍将其作为可部署战(类似于Jenkins)
war文件是使用Maven构建的,因此maven-war-plugin将主类(WebAppRunner)移到文件树的顶部,并覆盖war内部的所有jetty- * jar,javax * jar和spring-web.jar(可访问)到主类)并在META-INF / MANIFEST.MF中设置主类。
主类是这样启动Jetty的:
ProtectionDomain domain = WebAppRunner.class.getProtectionDomain();
URL location = domain.getCodeSource().getLocation();
WebAppContext context = new WebAppContext();
context.setContextPath( "/" );
context.setWar( location.toExternalForm() );
context.setParentLoaderPriority( true );
context.setConfigurations( new Configuration[] {
new AnnotationConfiguration(),
new WebInfConfiguration(),
new WebXmlConfiguration(),
new MetaInfConfiguration(),
new PlusConfiguration(),
new JettyWebXmlConfiguration()
} );
Server server = new Server( 8080 );
server.dumpStdErr();
server.setHandler( context );
try {
server.start();
server.join();
} catch ( Exception e ) {
LOG.warn( e );
}
Jetty本身启动就没有问题,并且在启动期间,WebAppContext会通过war文件中的WEB-INF / lib和WEB-INF / classes文件夹进行扫描,以获取SpringServletContainerInitializer作为ServletContainerInitializer的实现,而后者又应启动Web应用程序。
但是,AnnotationConfiguration.getNonExcludedInitializers方法找不到任何初始化程序(ServiceLoader返回空的可迭代)。
我在github上创建了一个小型演示项目来演示这一点(它使用MyAnnotationConfiguration覆盖了AnnotationConfiguration,仅添加了日志条目)。您可以使用以下命令进行构建:
mvn clean compile war:exploded antrun:run war:war
并运行:
java -jar target/myapp.war
或获取更多日志记录:
java -Dorg.eclipse.jetty.LEVEL=DEBUG -jar target/myapp.war
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句