[英]Runnable war with maven, jetty9, spring4 and no web.xml
我想使用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文件夾進行掃描 ,以選擇ServletContainerInitializer的實現來獲取SpringServletContainerInitializer ,這反過來又會啟動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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.