after a long struggle with JSFUnit, Maven and Eclipse, I finished writing a beginners tutorial, which targets for using JSFUnit with Eclipse:
It is targeted for this combination of tools:
-Eclipse 3.7 + Web Tools Platform plugin ("JavaEE developers" edition)
-JSFUnit 2 Beta 2 (built from source)
Note that I tried to use the Eclipse functionalities for developing and deploying JavaEE applications as much as possible and to use Maven only for places where there was no way around it ;-). This caused a bit of struggle to combine them both, but in the end it worked: I use Eclipse JavaEE project types, and only the test project is a Maven one.
The tutorial can be found here: http://www.cs.hs-rm.de/~knauf/JavaEE6/jsfunit/index.html
Any comments are welcome - and hopefully it is really helpful ;-).
do you deploy by using M2Eclipse or by using WTP (right click => "Deploy to server")? I assumed that the latter would not work, because WTP does not know about the changed structure of a Maven project. But maybe I just picked a wrong archetype?
I am a Maven beginner, so there are probably a lot of improvements to my tutorial.
Deploy using WTP.
The secret sauce in m2eclipse is pretty simple. When you 'Import a Maven Project' (Import->Maven->Existing Maven Project), m2eclipse reads the pom and sets the build properties of WTP and Java natures. For example, if your pom specifies a java 1.6 source and target, m2eclipse sets the right property in the java builder of eclipse. Same effect with m2eclipse-wtp. Your pom indicates war, ejb or ear package, which tells m2eclipse to adjust wtp builder from the pom values. If your pom does not redefine the default source directory, m2eclipse sets the wtp source directory to src/main/java. m2eclipse-wtp will also mark the project 'deployable' which makes it a candidate for 'deploy to server' (BTW, the path I usually take to deploy is to right click on the server and select 'Add/Remove...')
The conditions for successful import is to have m2eclipse, m2eclipse-wtp, and your pom must show a j2ee package type (war, or ejb).
Multi-module projects work, too.
I'm using this structure:
In app-ear/pom.xml, maven can be configured to generate the applications.xml file (or not).
It can be made to work, but some maven projects won't import well. I've stayed close to convention and have been successful so far.
Today I found the time to take a look at this again. Do you use this plugin: http://community.jboss.org/en/tools/blog/2011/08/01/m2eclipse-wtp-0131-back-to-the-m2e-marketplace ? If yes, I should start using JBoss Tools ;-).
What archetype do you use to create the projects? According to this tutorial (https://docs.sonatype.org/display/M2ECLIPSE/WTP+mini+howto ), it should be "maven-archetype-webapp". After this, I saw a "Dynamic web project" was created. And after some more struggling, I managed to set the required facets. But my managed bean didn't work. So, before digging further, I want to confirm that I installed the correct stuff ;-).
In some cases, I don't find latest plugins on marketplace. Marketplace is convenient, sure, but not always latest. I go to the project pages and confgure their update sites into my eclipse. Less convenient, yes, but almost always freshest.
I install plugins from m2eclipse and jboss tools projects. The latest available are the 'right ones'. Note that jboss tools has several 'maven configurators' which you should review and determine for your self if they apply to your projects. These will add facets as needed during import and is worth the added effort of installation.
The tutorial you quote is 3 years old. That doesn't automatically disqualify it, but it is long of tooth, as we say. The artefact is not complicated and ought to work. However, the artefact might be old, too, and may be using java 4 source/target, or a servlet api that is 'long of tooth', too. You can prove to yourself that maven by-command-line builds the project correctly, first. Then use m2eclipse import feature to pull the project into the eclipse IDE.
You will likely get more help on an m2eclipse forum at sonatype, or a jboss tools forum at jboss, than here on jsfunit.
thanks for the reply. So I installed JBoss Tools and found this archetype: https://docs.jboss.org/author/display/AS7/Creating+your+own+application
Using this archetype "jboss-javaee6-webapp" created a project with all required facets, but AS7 dependencies. I will do some more research, but up to now it seems quite nice.
What archetypes do you use? Do you know any ones which create the other JavaEE modules (EJB project, app client, EAR with multiple modules)?
This is more in line with how I expect things to work with eclipse and maven.
I'd throw in one more comment. You have a warning that the 'JSF' project has to be added in manually as an eclipse dependency of the 'JSFtest' project. This won't be necessary if the dependency is in JSFtest's pom.xml file:
Eclipse m2e plugin is smart enough to find this project in the eclipse workspace and add it to the 'Maven dependencies' for you.
However, the command line maven won't have such workspace awareness. Running from command line, it would be necessary to remember to run 'mvn install' for the JSF project, before 'mvn test' in the JSFUnit project. This is best resolved with a different project structure, instead of having two separate, isolated maven projects, JSF and JSFTest, make these submodules of a multimodule maven project.
Thanks for your comments again!
The "dependency" you suggested will not work in my "version 2" sample, because my JSF project is not mavenized and thus M2Eclipse cannot resolve it. So, version 1 of the sample is probably the better way. And maybe I will find a way to create a full EAR project one day ;-)