2015-10-14 22 views
1

我能夠成功地配置和使用這樣的pom.xml中jetty-maven-plugin配置啓動嵌入式碼頭,如何編寫一個Ant任務來啓動eclipse中的嵌入式jetty?

<plugin> 
    <groupId>org.eclipse.jetty</groupId> 
    <artifactId>jetty-maven-plugin</artifactId> 
    <version>${jetty.version}</version> 
    <configuration> 
     <stopKey>webappStop</stopKey> 
     <stopPort>9191</stopPort> 
     <httpConnector> 
      <host>localhost</host> 
      <port>9090</port> 
     </httpConnector> 
    </configuration> 
</plugin> 

我可以右擊該項目並運行Maven的目標,jetty:run和項目開始運行端口9090

[INFO] jetty-9.3.0.M1 
[INFO] No Spring WebApplicationInitializer types detected on classpath 
[INFO] Started [email protected]{HTTP/1.1,[http/1.1]}{localhost:9090} 
[INFO] Started @8012ms 
[INFO] Started Jetty Server 

現在,而不是右擊每一次運行Maven的目標,我需要編寫服務器啓動一個Ant任務和停止命令。

回答

2

創建以下簡單build.xml並創建兩個Ant任務來啓動和停止服務器,

build.xml

<project name="Demo Project" basedir="."> 

    <path id="jetty.plugin.classpath"> 
    <fileset dir="jetty-lib" includes="*.jar"/> 
    </path> 

    <taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" /> 

    <target name="jetty.run"> 
     <jetty.run /> 
    </target> 

    <target name="jetty.stop"> 
     <jetty.stop /> 
    </target> 

</project> 

項目的根目錄下創建一個jetty-lib文件夾,裏面放上以下罐子它,

javax.servlet-3.0.jar 
jetty-ant-9.3.0.M1.jar 
jetty-http-9.3.0.M1.jar 
jetty-io-9.3.0.M1.jar 
jetty-security-9.3.0.M1.jar 
jetty-server-9.3.0.M1.jar 
jetty-servlet-9.3.0.M1.jar 
jetty-util-9.3.0.M1.jar 
jetty-webapp-9.3.0.M1.jar 

更多abou t jetty-ant官方文檔中的配置。

+1

建議您使用Jetty的官方/穩定版本,而不是里程碑。如果您想要最新的穩定版本,請使用'9.3.5.v20151012'。 –

+0

@JoakimErdfelt感謝您的建議。我會更新我的pom.xml和jetty-lib * .jars。但是我無法通過''來停止服務器。如果我在jetty-stop之後運行碼頭運行,我仍然可以看到端口已打開並引發我[地址已在使用:綁定異常](http://stackoverflow.com/q/12737293/1793718)。我錯過了什麼嗎? – Lucky

相關問題