How do I configure a Java EE maven project in Eclipse? - eclipse

I know Maven pretty well, but I usually work with Netbeans, which makes it quite easy to deploy Java EE applications - and handle hot deployment of any changes.
The team I work with now uses Eclipse as their IDE of choice, but none of them has worked with Maven projects before; so I need to know how to correctly add Eclipse's project facets to the maven projects we have, in order to support (hot) deployment through WTP. We are using Weblogic 12c for this particular endeavour.
Our project layout is as simple as it gets:
super-project (pom)
project-ear (pom)
project-ejb (pom)
project-web (pom)
Thanks for any resource you can point me to.

I suppose that you've installed all required plugins to the Eclipse already. As #MichaƂ Politowski mentions, M2E, M2E-WTP and so on.
Add Archetype Catalog
Go to menu Window--->Preferences.
At the Preferences window, select Maven---->Archetypes,
On the Right Panel, click Add Remote Catalog... button.
At the Remote Archetype Catalog windows enter the following: -
Catalog file: http://repo.maven.apache.org/maven2
Description Maven Central
Add more remote catalog.
Catalog file: http://download.java.net/maven/2
Description Java.Net
Click OK to apply change.
Create the parent project
Go to menu File ---> New ---> Other.
At the Select Wizard Windows, select Maven ---> Project.
Click next and enter the required information so that we are at the New Maven Project.
At the Filter textbox, enter pom
Choose org.codehaus.mojo.archetypes:pom-root:1.1
Click next and enter the required information so that the parent creation is finished.
Create the child project
Right click at the parent project and select New ---> Other.
At the Select Wizard Windows, select Maven ---> Project.
Click next and enter the required information so that we are at the New Maven Project.
You will see that the Parent Project = MY PARENT
Enter the Module name, e.g. my-ear, my-ejb or my-web. Then click Next button,
At the Filter textbox, enter some of the following
org.codehaus.mojo.archetypes:webapp-javaee6:1.5
org.codehaus.mojo.archetypes:ejb-javaee6:1.5
org.codehaus.mojo.archetypes:ear-javaee6:1.5
Click next and enter the required information so that the child creation is finished.
Summary
I've used both NetBeans 7.x and Eclipse Juno together. When I move to Eclipse I've face the issue as same as your. Then I've captured the steps above from NetBeans logs one by one, and do the same thing manually by using Eclipse.
I hope this may help.

I would make one small change:
Create the child project
Right click at the parent project and select New ---> Other.
At the Select Wizard Windows, select Maven ---> **Maven Module**
This way it will automatically recognize this as a child project of the parent.

Related

How to run an eclipse m2e webapp project on a local server?

I'm trying to create a simple webapp as a maven project with m2e to help me manage dependencies, but I'm must be missing something, because I'm not able to run the project from eclipse.
To put a bit more context, here is what I do:
First, I choose to create a "Maven project"
Then, I select the "maven-webapp-archetype"
Finally, I fill the basic project information form of the next step and finalize project creation. Everything looks fine at this point.
The problem is that when I try to run the project, I don't find anything suitable to run the project on a local server:
Also, from the "Add and remove..." context menu entry of the local server, my project doesn't appear in the list of web projects.
Did I miss a step in the setup, or is there an other more suitable way to start the project?
You should install the m2e-wtp connector.
You can install this from: Window, Preferences, Maven, Discovery, click Open Catalog and search for wtp. Check the box next to m2e-wtp, and click Finish.
Once the installation process has completed, allow it to restart Eclipse. After that, you may need to right click on the project, choose Maven and Update project.

No HTTP Preview server for Eclipse Juno in Ubuntu 12.04

I just installed Eclipse Juno on Ubuntu 12.04 (32-bit) and downloaded the Eclipse Web Developer Tools. I created a new Static Web Project but cannot create/use HTTP Preview for the Target runtime to test/run my project. Does anybody know whether this is possible? If so, how would I do this?
You can create the patch and make it work for the Eclipse Juno version you have in the following four phases. Its a bit lengthy but it works
Phase 1: Create a plug-in project for the plug-in you need to patch.
Create a new workspace (recommended) or open an existing one.
Select File -> Import
Expand Plug-in Development, select Plug-ins and Fragments, then click Next
In the Import As section, select Projects with source folders
and then click Next.
Enter (or copy & paste, no quotes)
org.eclipse.wst.server.preview.adapter into ID field at the top and
click Add All. This should move this one plug-in to the right pane.
Click Finish to import the "org.eclipse.wst.server.preview.adapter"
plug-in source into a project.
Expand the root of the project and ensure it contains a folder named
"src". You will only get the "src" folder if you have the "WST Server
Adapter Plug-in Developer Resources" installed.
Phase 2: Apply the changes needed to update the plug-in. Since there is a bug with a patch attached that can be used to apply the changes, the following steps will take advantage of that.
Open Bug 402848 in a browser.
Click on the Patch v1.0 for 3.4.2p attachment link to open the patch.
Starting with the second occurrence of a line starting with ---,
select this line through the end of the text and copy it to the clipboard. This contains the changes to the PreviewLaunchConfigurationDelegate.java file which is where the fix is
needed. You don't want the upper portion of the patch as that would change the version of the plug-in, and that would complicate things.
Back in Eclipse, right-click on the "org.eclipse.wst.server.preview.adapter" project. Select Team and click on Apply Patch.
Leave Clipboard selected and click Next.
Ensure the "org.eclipse.wst.server.preview.adapter" project is
selected, and click Next.
Set the Ignore leading path name segments to 3. The "Patch
Contents" window should change to have a blue left pointing arrow
instead of red x indicators.
Click Finish to apply the changes.
Phase 3: Create the replacement jar. Due to the approach in Phase 1, the name of this jar will be identical to your current jar, which simplifies updating the Eclipse installation.
Right-click on the org.eclipse.wst.server.preview.adapter project in the Project Explorer or other navigator view and select Export
Expand Plug-in Development, select Deployable plug-ins and
fragments, then click Next
Click the Browse button next to the Directory selection in the Destination tab followed by OK. This will set the output directory to be the same as your workspace.
Click Finish to build the replacement plug-in jar. It will appear in
a "plugins" folder under the root of your workspace.
Phase 4: Replace the installed plug-in jar with the fixed version.
Exit Eclipse if it is running.
Under the "plugins" folder of your Eclipse installation, move or
rename the org.eclipse.wst.server.preview.adapter_1.1.101.v20121107_1651.jar if you
don't want to overwrite it with the patched version (mentioned in step 3 below). If you have a different version, it means you aren't using Juno SR2 and hopefully you installed the "WST Server Adapter Plug-in Developer Resources" that matched your version.
Copy the org.eclipse.wst.server.preview.adapter_1.1.101.v20121107_1651.jar from
the "plugins" folder under your workspace and paste it to the "plugins" folder of your Eclipse installation.
You should be able to run Eclipse now with the fixed plug-in. Because the patched jar had the same version number, no additional changes are needed.
I'm not familiar with the tooling you're using, but I had big problems with eclipse's internal browser on 12.04 as it was trying to use mozilla's XULRunner. The packaging of XULRunner has changed in 12.04 due to mozilla's release cycle, and isn't included in the repo independently. I forced my eclipse to use WebKit, by setting the following property in the vmargs section of my config.ini
-Dorg.eclipse.swt.browser.DefaultType=webkit
This sorted my issues out - hope this helps with yours.

Maven dynamic web project in eclipse deploys invalid jar files for dependent project(s)

I have a maven web project that imported into eclipse. I have another maven project (generates a jar file) that the web project depends on.
Both of these projects work correctly when executed from the command line. mvn package creates a war file which pulls the jar it depends on from the maven repository for the web project. mvn package creates a valid jar file when run for the library.
When I import the library into Eclipse, m2e recognizes that the web project depends on the library and updates parts of the project to take advantage of the fact that both maven projects are hosted within a single Eclipse workspace. The "Maven Dependencies" section of the "Libraries" tab of the "Java Build Path" preference for the web project removes the library jar file and replaces it with the library project. As the library is updated in Eclipse, the web project recognizes those changes without having to install/deploy the library.
The problem occurs when I attempt to run the web application in Eclipse. Because Eclipse is actually building the Web project against the version of the library in Eclipse, it does not deploy the library file from the maven repository, it creates a new jar file that's a snapshot of the current version of the library in Eclipse. All of this has generally worked well for me, but on the project I'm currently working on there's a problem with the jar file that Eclipse is creating. Instead of inserting the class files for the library, it appears that it's taking the "src" directory of my Maven project and zipping it up as the jar file. The contents of the jar file look something like:
-main
-java
-com
-... *.java
-resources
-...
-test
-java
-com
-... *.java
Where I would expect it to look more like:
-com
-... *.class
Since I have successfully used this type of project before, I'm trying to figure out if there's something I need to configure or if I've just run into a bug.
I'm using the latest update of m2e (1.0.200.20111228-1245) on Eclipse Indigo (Build id: 20120216-1857).
In Eclipse, we can disable the "Workspace Resolution" so that it will use our dependencies directly from the local maven repository as the following steps: -
Disable Workspace Resolution
Right click at the project inside the eclipse
Select "Maven" from the context menu.
If it display "Disable Workspace Resolution" which means it is enable. We click it with purpose to disable it. Please note, after that it will display "Enable Workspace Resolution" which means we have disabled already.
We may need to update the project configuration and other related dependencies as the following steps: -
Update Project Configuration
Right click at the project inside the eclipse
Select "Maven" from the context menu.
Click the "Update Project Configuration..."
The "Update Maven Dependencies" windows will be displayed.
Select the required projects and click "OK".
Update Dependencies
Right click at the project inside the eclipse
Select "Maven" from the context menu.
Click the "*Update Dependencies"
The "Update Maven Dependencies" windows will be displayed.
Select the required projects and click "OK".
Please take a note, since we not use the related dependencies directly from the workspace anymore, It will use directly from our local maven repository. Then all related artifacts should be installed to our local maven repository by using the following command line.
mvn install
Anyhow it can be done by using the context menu inside the Eclipse as the following steps:-
Right click at the project inside the eclipse
Select "Run As" ---> "Maven Install".
Here's the solution that I came up with.
It appears that in my case the rules for the "Deployment Assembly" for the library project are still followed.
To change it go to the library properties->Deployment Assembly
In my case that just contained a mapping from '/src' -> '/'. I removed that entry and replaced it with a mapping from '/target/classes' -> '/' and '/src/main/resources' -> '/'.
Once I had that mapping in place, when the jar file was deployed it contained exactly what I had configured in the Deployment Assembly. That allows Eclipse to continue to be used without explicitly republishing the library for every change. But, it doesn't seem to auto redeploy to tomcat for me when the library is updated -- I still need to manually restart tomcat for library changes to be reflected.
It's still not entirely clear to me what's going on with this project. I do have previous projects that have a similar structure, and in those projects the Deployment Assembly has not been updated to explicitly include the class files and yet the proper jar file is still deployed.

How do I import a multi module Maven project from SVN into Eclipse (Indigo) so that child modules can be built independently?

I have tried posting this question on the Eclipse Maven forums but it seems very quiet there so here goes...
My setup:
-Eclipse Indigo Java EE bundle
-m2e
-Subversive
We have a fairly simple multi module maven project on our repo. It has a parent project/pom and 3 child projects/poms.
Steps I am taking to import:
1) I import the project by using "import->import->->Maven->Check out Maven Projects from SCM".
2) On the next dialogue box I select svn as the SCM URL type and enter the rest of the repo URL. I leave the check boxes checked for "Checkout Head Revision" and "Checkout all Projects" and under "advanced" I leave the check box "Resolve Workspace Conflicts" checked too. I do not enter anything under "Profiles" or "Name Template".
3) On the next dialogue box I leave "Use default Workspace location" checked and leave "Add projects(s) to Working set" unchecked and click "finish".
4) I wait a minute or so for the next dialogue box to appear. It asks me to select maven projects and has a file structure as it should be-parent project/pom and 3 child projects/poms with a checkbox beside all 4 items. I have tried to select either just the parent, just the children or all 4 without success.
5) When I select just the parent and uncheck the children above, the project appears to be imported. The parent appears in the project explorer and the three children appear as sub-folders of the parent with each having a pom.
6) If I right click on the parent, I get a Maven item in the context menu and indeed I can "run as->Maven build, install etc.." ON THE PARENT ONLY. The Child projects have no such Maven context menus nor the ability to "run as->Maven x".
If I try to import all 4 projects in step 4 above, it imports with the same structure as outlined in 5 above but with the children appearing additionally as separate "independent" Maven projects (with errors).
Ultimately I just want to import the multi-module Maven project and be able to deploy it on my Eclipse Tomcat installation, so if I change a file in one of the child projects (called frontend) the change will be deployed quickly and I can check the effect out in a browser.
Thank you very much for any and all help with this issue! I am happy to answer any further questions to help trouble shoot the problem.
My projects occasionally also lose this ability (though they have it right after import). Usually it helps to refresh Maven configuration, refresh/clean projects, or restart Eclipse. Note that it should still be possible to run it the long way, so "Run -> Run Configurations -> Maven".
I'm running Helios SR 2, m2e 1.0.0.20110607-2117.
Pretty sure each module would have to have it's own .project settings that you would need to commit.
Did you install the m2e WTP extension? At least in theory that should be a better option than tinkering with project settings outside of Maven/m2e control.
I probably explained the problem poorly in my initial question. The main problem was that I was not able to deploy the webapp component of the multi-module maven project to Tomcat. I was making a couple of basic errors:
I was importing the parent project without selecting the children, assuming Maven would get them all and that would suffice, but it did not: I had to select the parent and all children when importing as Maven project from svn.
I then failed to convert the webapp part of the project to a faceted type, and further failed to select "dynamic web app". I needed (according to a colleague) to then select version 2.5 to avoid incompatibilities with older servlet containers. (not sure how relevant this is to Tomcat 6, which is what I use).
Once this was done I had the parent project and 3 subfolders and also the 3 child projects in their own right appearing in the project explorer (but on file system they all exist under the parent project, as it should be). I could then right click on the webapp module (the eclipse project explorer project, not the subfolder) and run as Maven project (clean, build etc.).
I could then right click and "run on server". I had an error upon publishing about various files being out of sync. I just refreshed the child projects in eclipse and then they would publish successfully.
Eclipse has so many versions, with so many incompatible plugins etc. that it gets confusing very quickly-lots of the tutorials are highly specific to particular versions etc.
Thanks for helping anyway guys.

Eclipse Generated Build Files

I am using the ZK Studio plugin to create a web based project based on the ZK framework. Now, in order to deploy this project, all I do is right click on the project and select "Export" then select "WAR file". However, I would like build files to be created so that someone else can just make a change and run the build file to re-compile and create the WAR file automatically. I have been told that Netbeans does this automatically, and it seems so does eclipse since it allows me to just say "Export as WAR". However, I need to commit build files to the svn as well. How can I get this option through eclipse?
Thanks!
P.S. I have seen this question:
Generating Ant build file for a project in eclipse
But I do not have that option when I right click for some reason.
Select build.properties file in project explorer view and from context menu (right click) select PDE Tools -> Create ant build file.
Same can be achieved through an ant task as well. See http://help.eclipse.org/helios/index.jsp?nav=/4_2_0