maven2 war overlay and eclipse WTP - java

I have a maven war module which run eclipse WTP tomcat server like normal. Now i want to reuse that module artifact by using maven war overlay: i just create a new war project and include that module in project dependencies. The problem is now i cannot use eclipse "Run on server" anymore because i don't have any resource or config file (like web.xml) in the new project, everything is in the war dependencies but eclipse cannot resolve it.
Is there anyway to use a maven war overlay project run with eclipse ?
Thank you.

If you're trying to have a war dependency on a war project, in other words doing a "war overlay", then it's not currently supported by m2eclipse
Jer developped a plugin to implement this feature, you can give it a try : http://code.google.com/p/m2eclipse-wtp-ext/

I've test this(to debug my first JASIG CAS server), and found it works in eclipse:
Using Jetty Maven Plugin to run/debug war overlayed web apps.
Hope helpful~

I am having the same issue here. I agree with you that it's not supported yet (and has not been for almost 2 years!). There seems to be an alternative using q4e version 0.11.0+: http://wiki.eclipse.org/IAM_WTP_support which you can download from https://code.google.com/p/q4e/ or using the update site http://q4e.googlecode.com/svn/trunk/updatesite-iam/ . I'll give it a try and see whether and how it works (with m2eclipse at the same time active).

Related

How to Move Maven Target Archive files into Server Deploy Folder?

I have a Maven, Java project with Eclipse and Jboss 4. Currently, after doing clean, install goals I am moving EAR and WAR files into Jboss Deploy folder manually. But every time this process hard to do. Are there any plug-ins or tools to do this job? I tried the "org.codehaus.mojo" plug-in but it did't work. Are there any other goals in Maven to deploy automatically to Server from Eclipse?
For such purposes you can use cargo which is intended for functional tests but supports the deployment of artifacts like ear, war into appropriate container.
may maven-war-plugin can help you

Best way to work with Java projects using Maven and Eclipse with embedded Tomcat?

I've run non-Maven applications on an Eclipse embedded Tomcat server before and I found the instantaneous deployment upon saving invaluable. However after starting a Maven project I didn't find any easy way to continue doing this.
Using WTP and the Dynamic Web Module Project Facet seems to wreck the project's Maven nature. Using JRebel is not possible in our company. Googling didn't provide any results that would work without again removing the project's Maven support. Is there any other way or am I doing it wrong?
Install m2elipse with WTP extension. Import your Maven WAR project. m2eclipse will configure Eclipse for and your can continue using your Tomcat in WTP.

GWT with Maven under Eclipse. What's the development cycle?

I am writing an application that uses GWT, some Spring MVC and Spring Security. Maven is be used to manage the dependencies and Eclipse is my IDE. I've created my application as follows:
webAppCreator -noant -maven -XnoEclipse -out MyApp com.example.MyApp
Then I've imported it into Eclipse as follows:
Imported as Maven project into Eclipse workspace.
In the project settings the "Use Google Web Toolkit" checkbox is ticked.
This project has a WAR directory" is checked. The WAR directory is set to src/main/webapp. The "Launch and deploy from this directory" is unchecked.
Then I test it's all OK:
Click run/debug, choose Web Application (the Google choice), and select target/www as the WAR directory.
So far, so good. Now I want to know how to control the development cycle. For example, I now want to add Spring to my application so I add this block to pom.xml and save it. The Maven Dependencies in Eclipse are expanded to show many new jars (Spring and its dependencies).
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
I also edit the web.xml to configure the Spring DispatcherServlet...
Once I've edited pom.xml and web.xml, clicking the debug/run icon on the toolbar will simply run from target/www again without any other steps taking place. This means the old web.xml is used, and target/www/WEB-INF/lib doesn't contain the Spring jars (and Spring's dependent jars). Do I need to drop to the command-line and issue Maven commands whenever particular changes are made?
The ideal answer will describe the development cycle for the above scenario.
My configuration:
GWT: 2.1.
Eclipse: Helios (3.6).
Maven: 2.2.1.
JRE/JDK: JDK 1.6.0.21.
Google Plugin for Eclipse 3.6 version 1.4.0.v201010280102.
Maven Integration for Eclipse (m2eclipse) version 0.10.2.20100623-1649 (this has been configured to point to Maven 2.2.1 environment and NOT to use the embedded Maven3 "instance").
I didn't understand you question completely but I use to create a separated gwt maven project and use apache web server to serve gwt files and then config my main webapp to load gwt files at client/browser. That save me from mixing gwt codes with my main webapp.
Edit regarding your comment:
Forget about gwt for start and read on ...
First you need to make sure that eclipse and maven are playing together correctly so that when you add dependency to you pom eclipse will recognize them too, and your eclipse project setup and structure match with maven.
Second you need to set up a web development configuration so that you can run/test your webapp. You can use maven jetty or tomcat plugin or eclipse tomcat server. IMHO using maven jetty plugin is better.
And Finally you need to package (using maven) and deploy (using maven or not) webapp to your deployment environment.
If you have been successful till now, then you can add gwt in using maven gwt plugin.
If you have installed eclipse maven plugin you can run maven commands from inside eclipse but it wouldn't hurt to run them from command prompt any way.

How to start/stop/redeploy maven web app using cargo start inside Eclipse

I have Maven2 war project built, I'm using the cargo start plugin, and it works great for deploying the web app. To run the maven command, I use a .bat file in my workspace, and I have en external run config to run the the bat file. I can't seem to stop the server from the Eclipse console, or re-deploy.
Does anyone have any advice on how quickly start/stop/re-deploy to Tomcat locally while developing.
Did you try JavaEE tools and m2eclipse? As far as I can see it should work well in most common situations. What m2eclipse does for you is to exactly map the maven configuration to an eclipse projects with the necessary facets set. Also, if the Dynamic Web Application facet is set for your project, you will be able to deploy it to a Tomcat server that you set up in the Server view of JavaEE tools. This configuration allows hot redeploy.
More information on JavaEE tools:
http://eclipse.org/home/categories/index.php?category=enterprise
There is a full Eclipse distribution with the EE tools available on their download site:
http://www.eclipse.org/downloads/
m2eclipse is freely available from Sonatype:
http://m2eclipse.sonatype.org/
At work we use the mentioned software as well. Additionally we use the JBoss tools that provide a feature called Project Archives that let you individually build your web application archive (ear/war/...).
To get startet you should perhaps start a fresh workspace and import the existing maven project (via the import existing maven project wizard). If everything went fine you can set up your tomcat in the server view. Maybe switch to the Java EE perspective. Right click on the newly added server and select Add to add the dynamic web project you just imported. If it doesn't show up in the list try to update the project configuration via the project's maven context menu.
Well, you could use cargo:redeploy to Undeploy and deploy again a deployable (that's a shortcut to cargo:deployer-redeploy). But I personally don't use Cargo this way, I use it mostly for integration testing (i.e. during the build) and use Eclipse WTP during development (this works whether you're using the maven eclipse plugin or m2eclipse).

How do I get maven managed dependencies copied into war\web-inf\lib so I can run my GWT 2.0 app in debug mode within Eclipse?

I am updating an existing project from GWT 1.5.2 to GWT 2.0.0. We use maven 2 to manage our dependencies and do all of our development in Eclipse 3.5.
Because we use maven to manage our dependencies, I do not have all of those jars in the war\web-inf\lib directory as GWT specifies. Instead, they are in the maven repository, just where maven likes them. I have the project set up so that maven can successfully build and launch in either dev or web mode and the application runs correctly.
The problem is that when I launch from Eclipse, I get a java.lang.NoClassDefFoundError. If I manually copy of my dependencies into war\web-inf\lib before launching, everything runs fine, but that doesn't lend itself to a long-term solution. First, if I check all of those jars into our version control, that will subvert much of the value we get from maven. As annoying as maven can be, ditching it is not the answer. Second, having developers manually copy them over every time they want to debug something is ridiculous.
So can I get Eclipse to copy the dependencies into war\web-inf\lib before launching? Is there an alternate solution that I'm missing?
Thanks,
Tony
Running the gwt:eclipse goal will copy the maven dependencies into war/WEB-INF/lib. See the Eclipse Configuration section of the Eclipse IDE Integration documentation of the Maven GWT plugin for more details. Also have a look at this answer about Maven GWT 2.0 and Eclipse.
You should install the m2eclipse plugin and use that to build your project within eclipse. This will invoke maven as an external tool from within eclipse.
Your maven project artifact type should be set to war, which will let maven discover the dependencies and bundle them.
See these links:
force Maven2 to copy dependencies into target/lib
http://maven.apache.org/plugins/maven-war-plugin/
http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html
a maven aware IDE (idea, eclipse, netbeans) should do this packaging automatically. maybe you:
forgot to enable maven import inside IDE?
did not add these dependencies to the pom.xml (so they aren't included in the 'mvn package' phase)
added wrong scope to dependency declaration (e.g. scope 'provided' or 'tested'), so they are ignored for runtime
If you have the packaging method in your pom.xml set to war it should copy runtime depdencies into target/war/WEB-INF/lib.
Or is your project to build something larger like an ear? If so you should probably split your pom.xml into multi-project format.
As for Eclipse, I'm not terribly familiar with it so I can't really help you there. Are you (or can you) run a maven target (like "install") when you do a run or debug?
This is not supposed to be a problem. If you are using Eclipse+WTP then WTP lets you declare jars listed under 'J2EE module dependency' in the project's properties. Those jars are automatically published to tomcat (see note at the end of this comment)
You need to declare an M2_REPO variable in your eclipse environment (search eclipse help for 'classpath variables'), it should point to your local maven repository, and just add external jars from there to your project and mark them as 'J2EE dependencies'.
I did that with tons of projects, Maven and Eclipse live side-by-side :) (without m2eclipse)
A second option is to try to integrate Eclipse and Maven with m2eclipse plugin, as crowne mentioned, but I found this unnecessary.
There is a third option, if you don't use WTP (but you should). Assuming that you use tomcat, then you can copy those jars to $(tomcat.home)/common/lib. If you can do it just for your private instance of tomcat (on each developer's machine) then you are good to go.
This is supposed to be a low-impact solution that will get those jars into the classpath at runtime, but it doesn't scale well.
note: unfortunately the classpath of Eclipse web projects can be confusing. When you add jars to the regular build path of the project, they are not deployed (copied over) to tomcat. To solve this, WTP defines a special library called Webapp Library - this library contains all the jars in the project's WEB-INF/lib folder, as well as all the external jars that are marked as J2EE Module Dependencies. All those jars find their way appropriately to WEB-INF/lib when published to tomcat.
Quite simple:
1. Create a "lib" folder under your project like this:
"\src\main\webapp\WEB-INF\lib"
2. Copy needed "jars" etc that you want included inside your WAR bundle folder.
3. Invoke your maven build as you normally do. I use "mvn install", which creates builds the war file.
If you examine the WAR file, your jars that you included in step-1 and step-2 will be there.
Cheers.

Categories