2005-07-25

Using Eclipse WTP 0.7RC2 with a maven project

When you want to develop web app on eclise, you have not many choices, but the picture is changing as the WTP project is reaching a stable build by the end of the month.
WTP is a very promising eclipse extension, that seems to have been very well though from the ground up, and from my point of view gives you better control than myEclipse (what I have been using so far).

It took me about a day to be able to use wtp 0.7rc2 with my maven projects. I couldn't find any relevant up to date documentation but some bugzilla entries and some outdated test plans. I am writing this post to not forget what I have been doing so far.

Basically a maven project is a project with the following features:
  • separation of sources by topic java, test, webapp
  • usage of external libraries with a variable (MAVEN_REPO)
  • eclipse project dependency where needed (<eclipse.dependency>true</eclipse.dependency>)
This tutorial only describes how to setup your eclipse project to use WTP to build a deployable webapp using separation of sources, externals jar and project dependencies.

[ArtifactId] will denote the current project name as per maven standards

This is still a very manual process, hopefully either the eclipse maven plugin or the mevenide eclipse plugin will be enabled to generate/edit/synchronize those configuration files.

Setup: eclipse 3.1 + wtp 0.7 RC2 or RC3
Of course you also need to install EMF/GEF/JEM plugins. I highly recommend installing in an extension directory (a directory with an eclipse subfolder and an empty file named .eclipseextension), so it is easy to switch versions and update to the latest version without having to reinstall eclipse from scratch.

I have two kind of projects, libraries and webapps. Libraries are used by webapps. This setup looks exactly like what is described by Integrating existing maven projects in WTP and by Flexible project test plan. But following those instructions written for WTP-M3 won't work with the current release of WTP.

I assume the projects are already setup as standard eclipse projects and compiling. To edit configuration files, you should switch to the resource perspective and disable "build automatically".

Step 1: setup the library projects
Edit .project there should be 3 builders in the following order:
  • org.eclipse.wst.common.modulecore.ComponentStructuralBuilder
  • org.eclipse.jdt.core.javabuilder
  • org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver
Then 2 natures in the following order:
  • org.eclipse.jdt.core.javanature
  • org.eclipse.wst.common.modulecore.ModuleCoreNature
(This step is optional) Edit .classpath (you can also do this through the interface) Change the default output folder to .deployables/[artifactId] for src/java.

Create a .wtpmodules file that contains the following code
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId">
 <wb-module name="[artifactId]">
  <module-type module-type-id="jst.utility"/>
  <wb-resource path="/"/>
 </wb-module>
</project-modules>

Step 2: setup the webapps
Edit .project and add the following builders
  • org.eclipse.wst.common.modulecore.ComponentStructuralBuilder
  • org.eclipse.jdt.core.javabuilder
  • org.eclipse.wst.validation.validationbuilder
  • org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver
  • org.eclipse.wst.common.modulecore.DependencyGraphBuilder
Add also the following natures:
  • org.eclipse.jem.workbench.JavaEMFNature
  • org.eclipse.jst.j2ee.web.WebNature
  • org.eclipse.jdt.core.javanature
  • org.eclipse.wst.common.modulecore.ModuleCoreNature
Edit .classpath so that your ouput folder for src/java is .deployables/[artifactId]/WEB-INF/classes.

Create a file .wtpmodules which reads
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId">
 <wb-module deploy-name="[artifactId]">
  <module-type module-type-id="jst.web">
   <version>2.3</version>
   <property name="context-root" value="[artifactId]"/>
   <property name="java-output-path" value="/bin/"/>
  </module-type>
  <wb-resource source-path="/src/java" deploy-path="/WEB-INF/classes"/>
  <wb-resource source-path="/src/webapp" deploy-path="/"/>

  <dependent-module deploy-path="/WEB-INF/lib"
    handle="module:/resource/[libArtifactId]/[libArtifactId]">
   <dependency-type>uses</dependency-type>
  </dependent-module>
  <dependent-module deploy-path="/WEB-INF/lib"
    handle="module:/classpath/var/MAVEN_REPO/[groupId]/jars/[artifactId]-[version].jar"/>
 </wb-module>
</project-modules>

The handle protocol is as follow:
  • classpath is a classpath reference, the second item on the path can be lib or var (as the kind attribute in the .classpath file)
  • resource is an eclipse flexible project reference, the second item being the project name, and the third item a module within the project. dependency-type can be uses which build the jar for you or consumes which copy the files across.
To generate your .wtpmodules file you can copy/paste the section of .classpath which contains references to external jars and replace [classpathentry kind="var" path="] by [dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/var/]

You can now enable "automatic building", and your webapp should be assembled in the .deployables directory. You can then rigth-click your webapp project icon and Run it on the server of your choice.

This is a very error prone process, as there is no error or warning if you provide a broken .wtpmodules file.

Any comments appreciated.

16 comments:

Anonymous said...

Great explanation of modules definition, thanks. it even works for the final release of WTP 7.0

Anonymous said...

Is there a way to do a simple copy from anywhere from my eclipse project to anywhere to .deployables directory ?
I nee that because my web.xml file is in the conf directory of my eclipse project and I need to deploy it in .deployables/WEB-INF.

Mirco Attocchi said...

very usefull. I use for automate coping some .jar in /WEB-INF/lib

Roberto Iza Valdés said...
This comment has been removed by a blog administrator.
Anonymous said...

Worked for me (M8, WTP 0.7), thanks!

Richard said...

When I do this, it correctly creates files under my .deployables/Project/WEB-INF/lib directory, but they don't have the .jar suffix. If I rename them then Tomcat will see them, if not then it doesn't. I could swear that this worked the last time I tried it, too. Any help would be very much appreciated.

yadong.biz said...

I accidentally searched and visited your site. I still saw several posts during my visit, but the text was neat and readable. I will quote this post and post it on my blog. Would you like to visit my blog later? Feel free to visit my website;
일본야동
일본야동
국산야동
일본야동
한국야동

yahanvideonet said...

Wonderful items from you, man. I’ve have in mind your stuff previous to and you’re just extremely excellent. I actually like what you’ve acquired here, really like what you’re saying and the way in which through which you assert it. You’re making it entertaining and you still care for to keep it smart. I cant wait to read far more from you. That is actually a terrific web site. Feel free to visit my website;
일본야동
일본야동
국산야동
일본야동
한국야동


koreayadongcom said...

Hello there, You have performed an excellent job. I will definitely dig it and personally suggest to my friends. I’m confident they will be benefited from this web site. Feel free to visit my website;
일본야동
일본야동
국산야동
일본야동
한국야동

chinayadongnet said...

Hard to ignore such an amazing article like this. You really amazed me with your writing talent. Thank for you shared again. Feel free to visit my website;

일본야동
일본야동
국산야동
일본야동
한국야동

japanyadongcom said...

Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web! Feel free to visit my website;
일본야동
일본야동
국산야동
일본야동
한국야동

javmost said...

ดูหนัง av ญี่ปุ่น jav เอวีซับไทย หนังโป๊ ฟรี ตลอดทั้งปี av th แหล่งรวม หนัง xxx เล่าเรื่องเสียว ที่จะทำให้คุณได้รับความเพลิดเพลินในการรับชม javmost

Anonymous said...

ufabet1688x สมัคร เว็บแทงบอลออนไลน์ ยูฟ่าเบท ที่ได้มาตรฐานระดับโลก เว็บ UFABET มือถือ ที่ดีที่สุดในประเทศไทย แทงบอลออนไลน์ คาสิโน บาคาร่า สล๊อต ufabet เข้าสู่ระบบ

Anonymous said...

บริการทุกระดับประทับใจ เลือกเล่น betflixsupervip มีหลากหลายเกมสล็อต ไม่ว่าจะเป็น สล็อต joker, pgslotgame , super-slot ที่หาเล่นได้ทั้งหมดจาก betflixsupervip ของเรา ทางเราเปิดบริการตลอด 24 ชั่วโมง ฝากถอนได้ดั่งใจ betflix

Anonymous said...

ที่สุดแห่งบาคาร่าออนไลน์ biobetgaming บริการตลอด 24 ชั่วโมง บริการด้านเกมคาสิโนหลากหลายเช่น บาคาร่าออนไลน์ รูเร็ท แบล็คแจ็ค เสือมังกร ไฮโล และอื่นๆอีกมากมาย ที่มาพร้อมกับโปรโมชั่นโดนใจเน้นๆ ที่นี่ที่ biogaming

Anonymous said...

เดิมพันออนไลน์กับเว็บเราสิ AMBBET168X ยินดีให้บริการ เราเป็นเว็บตรงจากต่างประเทศจริง เราไม่ได้มาเล่นๆ แต่เราจริงจัง จัดเลย ambbet พร้อมบริการตลอด 24 ชั่วโมง ปลอดภัยไร้กังวล 100%