您的位置:首页 > 产品设计 > UI/UE

this is a good article guide you devolop with maven & jetty

2012-01-26 08:59 483 查看

RapidRESTDevelopmentwithmavenjettyplugin

http://jlorenzen.blogspot.com/2010/02/rapid-rest-development-with-maven-jetty.html

Tuesday,February16,2010

RapidRESTDevelopmentwithmavenjettyplugin

EverwonderhowmuchtimeiswastedbyJavadevelopersrebuildingandredeployingwebapplications?FormealoneIcan'timagineit.Infact,I'dbeembarrassedifGoogleBuzzmadeitpublicknowledgewithoutmyconsent.TwoyearsagoIwroteanarticle"NomoreJ2EEApps"andIreceivedalotofgreatfeedback.LetmefirstsaythatIthink,IMHO,JavaDevelopersareatadisadvantagewhenitcomestorapidlydevelopingwebapplicationswithastaticlanguage.Developersusingpython,php,rails,orgrailsreallydon'tevenhavetospendasecondtryingtosolvethisproblem.Ontheotherhand,JavaDevelopershavetofigureouthowtobestaccomplishthis,andeverysituationseemstobedifferent:JBoss,Weblogic,Eclipse,Idea,Netbeans,Jetty,JRebel.OfallthesolutionsIthinkJRebelprovidesthebestchanceforsuccessthatsolvesanyenvironmentnomatterthewebcontainerordevelopersIDEofchoice.

Ihaven'treallydonemuchhardcorejavadevelopmentinawhile,butinordertoimprovemyteam'sproductivity,Iamgoingtobeexploringbestpracticesthenextcoupleofmonthsconcerningthisarea.Firstup,IamgoingtoexplainhowIgotthemavenjettyplugintoworkwithourRESTServicesWARandthestepsnecessarytoredeploychanges.Thenicethingaboutjettyisit'seasytousefrommavenandwecoulduseitinourCIenvironmenttopossiblyreduceourbuildtimesandprovidequickerfeedback.ThedownsideiseachchangerequiresjettytohotdeploythenewWAR.EndtheendIthinkthebestsolutionwillbeacombinationofJBoss+JRebel.ButIwon'tgettoforawhile.

MavenJettyPlugin
Myfirstprototypeusesthemaven-jetty-pluginversion6.TheapplicationwearetestingisaWARcontainingRESTServicesbuiltwithJersey(JAX-RS).Hereisagoodpostingbymyco-workerJeffBlack"Jersey...JettyandMavenstyle!".Thisexampledidn'tworkformebecauseforsomeinsanereasontheinit-param,com.sun.ws.rest.config.property.packages,doesnotworkinWebSphere.SoIhadtodosomeslightmodificationstogetittoworkwithoutthatbeingdeclared.Mypom.xmlandjetty.xmlfilesarebelow.Most"normal"non-Jerseyapplicationsdon'tneedallofthis,butitwasnecessarytogetourlegacyWARworkingwithjetty.

Herearethestepsinvolvedtostartjettyandredeploychanges:

mvninstalljetty:run-thiswillfirstbuildtheWARandthenstartjettywhilealsodeployingtheWAR.RunninginstallwasnecessarybecauseIreferencetheexplodedWARdirectoryundertargetinthejettyconfiguration.
Makechangestosourcecode
Run"mvncompilewar:exploded"inaseparateterminaltocompileyourchangesandcopythenewclassfilestothelocationJerseyexpectstofindthem.Whichinmycaseis/target/myapp/WEB-INF/classes
ClickbacktotheterminalrunningjettyandhittheENTERkey.ThiscausesjettytoreloadtheWAR.ThisisbecausebydefaultIsetthescanintervalto0andjetty.reloadtomanual,soIcanbatchupmultiplechangesbeforereloading.
OverallIamhappywiththeresultssofar.Previously,ittook1-2minutesandsometimesmoretorebuildthewarandhotdeploytoJBoss.Usingthejettypluginthisnowtakesaround30seconds.Again,IthinkthiscouldbefurtherimprovedbyusingJRebel.

Tips
IdidhavetoupdatemyMAVEN_OPTSenvironmentvariabletoincreaseJava'sPermGenSpacesincejettyreloadstheWAReachtimeandyou'llquicklyrunoutofmemory.ThiswassomethingIwasalreadydoinginJBoss.Hereiswhatitissetto:

exportMAVEN_OPTS="-Xmx1024m-XX:PermSize=256m-XX:MaxPermSize=512m"

SampleFiles
Hereismypom.xml
01
<
plugin
>
02
<
groupId
>org.mortbay.jetty</
groupId
>
03
<
artifactId
>maven-jetty-plugin</
artifactId
>
04
<
version
>6.1.22</
version
>
05
<
configuration
>
06
<
jettyConfig
>${project.build.testOutputDirectory}/jetty.xml</
jettyConfig
>
07
<
scanIntervalSeconds
>${jetty.scan.sec}</
scanIntervalSeconds
>
08
<
useTestClasspath
>true</
useTestClasspath
>
09
<
webAppConfig
>
10
<
baseResource
implementation
=
"org.mortbay.resource.ResourceCollection"
>
11
<
resourcesAsCSV
>${project.build.directory}/myapp</
resourcesAsCSV
>
12
</
baseResource
>
13
</
webAppConfig
>
14
<
systemProperties
>
15
<
systemProperty
>
16
<
name
>jetty.port</
name
>
17
<
value
>${jetty.port}</
value
>
18
</
systemProperty
>
19
</
systemProperties
>
20
<
systemProperties
>
21
<
systemProperty
>
22
<
name
>jetty.reload</
name
>
23
<
value
>${jetty.reload}</
value
>
24
</
systemProperty
>
25
</
systemProperties
>
26
</
configuration
>
27
<
dependencies
>
28
<
dependency
>
29
<
groupId
>commons-dbcp</
groupId
>
30
<
artifactId
>commons-dbcp</
artifactId
>
31
<
version
>1.2.1</
version
>
32
</
dependency
>
33
<
dependency
>
34
<
groupId
>net.sourceforge.jtds</
groupId
>
35
<
artifactId
>jtds</
artifactId
>
36
<
version
>1.2</
version
>
37
</
dependency
>
38
<
dependency
>
39
<
groupId
>com.oracle.jdbc</
groupId
>
40
<
artifactId
>ojdbc14</
artifactId
>
41
<
version
>10.2.0</
version
>
42
</
dependency
>
43
</
dependencies
>
44
</
plugin
>
45
.....
46
<
properties
>
47
<
jetty.port
>8080</
jetty.port
>
48
<
jetty.scan.sec
>10</
jetty.scan.sec
>
49
<
jetty.reload
>manual</
jetty.reload
>
50
</
properties
>
Hereismyjetty.xmllocatedunder/src/test/resourcesusedtodefinetheDatasource.
01
<?
xml
version
=
"1.0"
?>
02
<!DOCTYPEConfigurePUBLIC"-//MortBayConsulting//DTDConfigure//EN""http://jetty.mortbay.org/configure.dtd">
03
04
<
Configure
id
=
"Server"
class
=
"org.mortbay.jetty.Server"
>
05
06
<
New
id
=
"MYAPP-DS"
class
=
"org.mortbay.jetty.plus.naming.Resource"
>
07
<
Arg
>jdbc/MYAPP-DS</
Arg
>
08
<
Arg
>
09
<
New
class
=
"org.apache.commons.dbcp.BasicDataSource"
>
10
<
Set
name
=
"driverClassName"
>oracle.jdbc.driver.OracleDriver</
Set
>
11
<
Set
name
=
"url"
>jdbc:oracle:thin:@localhost:1521:XE</
Set
>
12
<
Set
name
=
"username"
>user</
Set
>
13
<
Set
name
=
"password"
>password</
Set
>
14
</
New
>
15
</
Arg
>
16
</
New
>
17
18
</
Configure
>
Postedbyjlorenzenat11:45PM

Labels:jersey,jetty,maven,rest


Disqus
Like
Dislike

Login

AddNewComment



Image

Showing3comments



RonnyNicepost:)
Ifindusingmvnjettypluginormvntomcatpluginarealtimesaver.
Justaminornote;Ithinkoracle.jdbc.driver.OracleDriverisdeprecated,infavoroforacle.jdbc.OracleDriver.Like
Reply
1yearago



jlorenzenThanksRonny.Iactuallywasn'tawarethatdriverwasdeprecated.Thanksforthetip.DoyouhaveanyreferenceinformationIcouldreadtogetcaughtup?Like
Reply
1yearago
inreplytoRonny



RonnyLookslikeithasbeendeprecatedforawhile,andisnowremovedin11g.
http://www.oracle.com/technolo...,section"Desupportoforacle.jdbc.driver"

Aneasychangethough,justusepackageoracle.jdbcinsteadoforacle.jdbc.driverLike
Reply
1yearago
inreplytojlorenzen

MSubscribebyemail
SRSS
blogcommentspoweredbyDisqus

Linkstothispost

CreateaLink
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐
-->
新的分享
章节导航