2014-12-05 51 views
1

我與創造的最基本的運行碼頭應用程序,在同一時間推出的.war包的例子掙扎。我找到的所有東西都只是說將.war放在「$ JETTY_HOME/webapps」中,但我不確定如何驗證「$ JETTY_HOME」是什麼。我試圖擴展在https://github.com/heroku/java-getting-started.git發現的簡單heroku默認應用程序。我的目錄結構:運行的.war文件與碼頭

src/ 
-- main/ 
---- java/ 
------ Main.java 
target/ 
-- (lots of stuff in here) 
pom.xml 
Procfile 
webapps/ 
-- workbench.war 

我跑我的java -cp target/classes:target/dependency/* Main應用。

Main.java是相同的:https://raw.githubusercontent.com/heroku/java-getting-started/master/src/main/java/Main.java

我怎樣才能得到這個應用程序運行的.war文件?每當我訪問localhost:5000/workbench時,我只會看到「Hello World」,我應該看到workbench.war中包含的Workbench應用程序。

+0

該示例根本不使用war文件,它使用直接的Servlet定義。 – 2014-12-05 20:49:32

+0

我想擴展這個「例子」,所以它可以做到這一點。 – 2014-12-06 14:45:27

+0

圍繞Web應用程序的「上下文」意味着您需要擁有該上下文中的所有內容,否則它將成爲不同的上下文。記住當你決定你想要做什麼時。將自動構建的戰爭上下文與其自動加載的描述符和一些手動servlet混合在一起很困難(但並非不可能)。 – 2014-12-08 12:42:06

回答

1

如果它只是一個單一的戰爭,做到這一點。

package org.eclipse.jetty.demo; 

import org.eclipse.jetty.annotations.AnnotationConfiguration; 
import org.eclipse.jetty.plus.webapp.EnvConfiguration; 
import org.eclipse.jetty.plus.webapp.PlusConfiguration; 
import org.eclipse.jetty.server.Server; 
import org.eclipse.jetty.webapp.Configuration; 
import org.eclipse.jetty.webapp.FragmentConfiguration; 
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; 
import org.eclipse.jetty.webapp.MetaInfConfiguration; 
import org.eclipse.jetty.webapp.TagLibConfiguration; 
import org.eclipse.jetty.webapp.WebAppContext; 
import org.eclipse.jetty.webapp.WebInfConfiguration; 
import org.eclipse.jetty.webapp.WebXmlConfiguration; 

public class EmbedMe 
{ 
    public static void main(String[] args) throws Exception 
    { 
     int port = 8080; 
     Server server = new Server(port); 

     String warpath = "webapps/workbench.war"; 

     WebAppContext context = new WebAppContext(); 
     context.setResourceBase(warpath); 
     context.setConfigurations(new Configuration[] 
     { 
      new AnnotationConfiguration(), 
      new WebInfConfiguration(), 
      new WebXmlConfiguration(), 
      new MetaInfConfiguration(), 
      new FragmentConfiguration(), 
      new EnvConfiguration(), 
      new PlusConfiguration(), 
      new JettyWebXmlConfiguration() 
     }); 

     context.setContextPath("/"); 
     context.setParentLoaderPriority(true); 
     server.setHandler(context); 
     server.start(); 
     server.join(); 
    } 
} 
+0

這看起來很有前途 - 這將允許我運行戰爭並聽取其他路線嗎? – 2014-12-06 14:49:51

相關問題