maven 中使用jetty原始文章
- Using the Maven Jetty plugin
- Configuring HowTo
- Running
- Running the webapp in debug mode using Java Platform Debugger Architecture (JPDA)
- Attaching
to the server running in debug mode, using eclipse:
- Configuring HowTo
Using the Maven Jetty plugin
This note is to describe the above plugin. which will run your web application in an embedded Jetty6 instance by just
typing "mvn jetty:run" - No need to download or install Jetty manually, it's all automatic once the Maven project
descriptor's set up (the pom.xml)
Configuring HowTo
Add the following to the <build><plugins> block of your projects pom.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
Running
In order to run Jetty on a webapp project which is structured according to the usual Maven defaults, you don't need to configure anything.
Simply type:
mvn jetty:run
Due to a bug
in maven or the maven-jetty-plugin this only works if no jetty artifact
is present in the dependencies section of the pom.xml file. This is the
case for wicket-quickstart, wicket-examples and wicket-threadtest. So
the tips given here can't be applied to those projects.
Running the webapp in debug mode using Java Platform Debugger Architecture (JPDA)
Using maven command line:
I couldn't find a command line reference for maven2, but the one given for maven1 still aplies for the feature used here:
First set MAVEN_OPTS environment variable with the following command:
export MAVEN_OPTS='-Xdebug -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y'
After setting this property, run "maven jetty:run" and it will block, waiting for a debug connection. If "suspend=n" is set, it will start right away.
Using eclipse external tools
:
Running Eclipse Open "Run --> External Tools --> External Tools... --> Program". Press "New launch configuration". On the "Main" tab, fill in the "Location:" as the full path to your "mvn" executable. For the "Working Directory:" select the workspace that matches your webapp. For "Arguments:" add jetty:run.
Move to the "Environment" tab and click the "New" button to add two new variables:
name | value |
---|---|
MAVEN_OPTS | -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y |
JAVA_HOME | Path to your java executable |
As above the jvm will start right away when "suspend=n" is set.
Attaching
to the server running in debug mode, using eclipse:
Running Eclipse Open "Run --> Debug... --> Remote Java Application". Press "New launch configuration". Fill in the dialog by selecting your webapp project for the "Project:" field, and ensure you are using the same port number as you specified in the address= property above.
Now all you need to do is Run/Debug and select the name of the debug setup you setup above.
This article is a gathering of information, credits need to be given to the authors of the pages behind the given links.
Eclipse中用Maven來(lái)啟動(dòng)Jetty調(diào)試Web應(yīng)用
1、先來(lái)配置一個(gè)外部工具,來(lái)運(yùn)行JETTY:
選擇菜單Run->External Tools->External Tools ...在左邊選擇Program,再點(diǎn)New:
配置Location為mvn完整命令行。定位到bin下的mvn.bat
選擇Working Directory為本項(xiàng)目。
Arguments填寫:jetty:run
再點(diǎn)選Enviroment頁(yè):加入MAVEN_OPTS變量,值為:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8080,server=y,suspend=y
其中,如果suspend=n 表示不調(diào)試,直接運(yùn)行。address=8080為端口
然后,點(diǎn)APPLY,點(diǎn)擊Run啟動(dòng)jetty
2、調(diào)試應(yīng)用
點(diǎn)選run->debug...
選中左樹中的Remote Java Application,再點(diǎn)New。
選擇你的項(xiàng)目,關(guān)鍵是要填和之前設(shè)置外部工具時(shí)相同的端口號(hào),其它都不變。
注意:停止調(diào)試后,8080端口并沒有關(guān)閉,再運(yùn)行run->debug后會(huì)報(bào)錯(cuò),具體原因沒有去深究。建議采用TcpView等工具關(guān)閉對(duì)應(yīng)端口的進(jìn)程
posted on 2009-02-14 17:37 草原上的駱駝 閱讀(1294) 評(píng)論(0) 編輯 收藏 所屬分類: 項(xiàng)目管理