I have a multi-module Maven project that makes use of WAR overlays (stack of them 3 deep). Everything works great in Maven, but I am unable to launch my WAR from within Eclipse because it complains of not finding various files.
How can I configure Eclipse (and a launcher) so that I can run my WAR from Eclipse without having to do a Maven Install first? I should add that my Eclipse WAR projects are not dynamic web projects...is that a part of what I need to do?
NOTE: The following question touches on the subject, but the answer indicates you must always do a Maven install first and I know that can't be right because there are folks that use Eclipse without Maven.
Maven overlays and Eclipse
I've also found this which makes me think it is not possible via vanilla M2E:
http://jira.codehaus.org/browse/MNGECLIPSE-599
I was able to accomplish this and everything works great. Here's what to do:
First of all you need the M2E Eclipse plugin which is needed to have Eclipse automatically recognize and update Maven dependencies. It also provides a nice graphical POM editor. As of late 2011, the M2Eclipse project was donated to the Eclipse foundation by Sonatype and is now called simply M2E. However, it is still not shipped with the Java EE edition of Eclipse Indigo and must be installed separately via their update site
http://download.eclipse.org/technology/m2e/releases
In the past, the integration between Eclipse and Maven has been somewhat troublesome. However, this new Eclipse based Maven integration is now aware of the fact that there are many Maven plugins used within POM files and that only certain goals of certain plug-ins make sense within an IDE environment. Furthermore, those goals that do make sense when running inside an IDE may need special configuration. To properly handle this M2E now supports the notion of a "connector"
M2E has a long list of special connectors that allow it to do the "Right Thing" when invoking various mojos (Maven plugin goals). To see the list of available connectors within Eclipse go to the Preferences dialog and select Maven->Dicovery->Open Catalog. These connectors are supposed to be installed automatically when detected within a {{pom.xml}} file during project import. However, this requires the correct version of the M2E Maven import wizard (which Indigo does not have until SR2).
In addition, sometimes these connectors are buggy and we need to use the nightly or beta updates sites to get the latest fixes. If you have an older or buggy version, then you need to delete and re-import the projects after upgrading. For these reasons, in my opinion, all M2E connectors should be installed by hand prior to importing the your project into Eclipse.
The M2E-WTP connector is the one you need to make WAR overlays work in Eclipse launchers for Eclipse "Servers". This connector is used to integrate Maven with WTP...and thus handles WAR overlays, servlet container setup, Eclipse WTP configuration, root context setting, and other things that all go towards making Eclipse web tooling "Just Work" when a Maven WAR module is imported into Eclipse as a project.
The update site for the m2e-wtp connector is: http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
Add this M2E-WTP site and install the connector. Note however, that neither M2E nor the M2E-WTP connector are going to put dependencies of the overlay WAR into the final WAR. You must do this by adding required dependencies to the final WAR pom.xml. I don't know why the tools don't do this, but they don't -- so just get over it. ;-)
At this point, I would also recommend doing a full update via {{Help->Check for Updates}}. Once this is done, you should be able to simply add an Eclipse server, click on your project (not the overlay one, but they regular one) and choose "Run on server...".
Changes made to either the WAR or the overlay WAR will be automatically published to your server. Javascript changes are published without restarting the server...all you have to do is hit refresh in the browser to see the new code running.
Second Update: There is a bug (https://issues.sonatype.org/browse/MECLIPSEWTP-174) in M2E which can result in the WEB-INF/lib directory accidently losing all its JAR files. When this happens, your servlet application will obviously not start. The workaround is to clean the server by clicking right on the server and selecting "clean". Note that cleaning the work directory alone will not restore these missing JARs.
Related
I work on a big Java application and I'm having problem compiling it under Eclipse Kepler:
the application is based on Maven 3.1.0 and successfully compiles there
I generate Eclipse configuration (project files) using mvn eclipse:eclipse
The problem is that certain classes present in more than one JAR (e.g. imagine a class Http and two versions of this class where newer has more methods) and Eclipse makes a wrong choice of the depending class (older one) for particular project which makes it not compilable.
I tried to move Jars up/down in the project dependencies and it helps in certain situations, however, it means that I'm changing configuration changed by Maven.
Is it possible to configure Eclipse so that is "smarter"? Is it caused by Maven (POM files, a bug in Maven's eclipse plugin, ...) although maven compiles the project without any problems? Any other suggestion?
You should not use mvn eclipse:eclipse. The official way today is to use the m2e plugin (which is much smarter) with File->Import->Existing Maven projects.
When you open a pom.xml file you can see the dependency hierarchy and why a given jar was chosen.
(Note that most but not all standard distributions of the latest Eclipse contains m2e. If your do not you can download it from the marketplace, but it may be easier to download a distribution that has it).
i was on a 2-day training introducing as to Java EE. We used there Java EE, Spring Framework, Maven, Springsource Tool Suite (Eclipse), Tomcat.
I took the Eclipse workspace we created there and run it on my work PC. I had, if i remember correctly, only to configure Tomcat properly, and it worked on my PC.
Now i want to save the created Eclipse workspace containing 5 "sub"-projects in subversion so that my work colleagues can checkout this to them and run it on their computers.
How to do this correctly? I found somewhere a svn:ignore rule:
.classpath
.project
.settings
target
Using tortoiseSVN i added to the folder with the workspace this ignore rule, but the found out that the underlying folders target were'nt deleted so i deleted them manually and "added to ignore list". But after that the project in spring source tool suite does not see the mevan dependencies (i think so) because the imports are broken. STS underlines org. in the imports and says it can not resolve this.
How do i correctly version control such a project?
In my project we are using Maven and Eclipse (Helios, currently) and the Maven plugins for Eclipse:
Maven Integration for Eclipse
Maven Integration for WTP
We only have the pom.xml file and the src/ directory tree in our version control system. We make sure not to add the eclipse files there. Then when a new developer starts in the project they do Import -> Maven -> Existing Maven Projects. The Maven plugins for Eclipse then set up perfect build paths, settings and so on.
This way it is also very easy to re-import your projects into Eclipse as needed.
So, my tip is to leave the Eclipse files out of SVN and make sure you can setup the project correctly automatically simply by importing a Maven project.
If I understand your problem the right way, you need to configure Eclipse in order to be able to launch tomcat from it. The key, here, is not maven anymore, but Eclipse, I think. As you've made modifications in your workspace that can't be put in your maven configuration file (the pom.xml), you become "Eclipse dependant".
The key here is that, as you're Eclipse dependant, you need the Eclipse configuration files to work. Consequently, I'm afraid you need to add back .classpath, .project, .settings to your versioning tool... It's not generic, because you force people who work on your project to use Eclipse. But if everybody in your team do so, it shouldn't be a problem.
As I don't use Eclipse anymore, I don't know if versioning theses files can lead to problems. However, I hope this answer will help you to configure your project back...
EDIT : to be more accurate... and maybe give a better answer.
When using a version control system, the main goal is often (always ?) to give all the keys to use the sources, and develop from them. Consequently, you need to put in your VCS your sources, and all the configurations needed to use them efficiently.
In your specific case, the key is that you've become Eclipse dependant through its Springsource Tool Suite plugin. Consequently, it becomes essential to add the configuration files for this tool, because they can't work without them, and if they can't work, you can't work.
I can tell you my way of subversioning maven eclipse projects. First, when you create the project structure you have to commit the .setting, .classpath, .project files into the subversion repository. If you can't do this the other colleagues will can not use the project structure after checkout. After you commit the project structure, the best way is not to commit these files except only when you change something important eclipse or build path settings, because the others will have conflicts due to the system dependent informations. Never commit the maven target directory. Sorry for my english. Hope it helps.
I have been working solo on a project for some time, and now, new developers are likely to join the project for various reasons.
I, of course, use a version control software but I am afraid importing my project into Eclipse and making it run might prove a little difficult for new comers, and I want to make it as clean as possible.
When I first took over the project, it took me almost two days to have the project built and run it, I documented every step and fixed the most obvious errors, but not all, and I want the project to run as it is when imported.
The project is a mix of java projects for the backend, a j2ee project for the server and a flex project for the client.
The IDE is going to be Eclipse
The version control software is Perforce
Here are some of the specific problems I have right now, should I fix them, and how ?
Eclipse environment variables are used for libs, all the libs are in a folder in the j2ee project but are used by all the java projects (they have to be set in each IDE the project is imported into)
Runtime JRE is specified in .classpath for each project, so each projects property must be edited when trying to build the project in another environment
Apache server is specified in j2ee project property
To avoid exporting the jars of all the java projects into the j2ee project each time I modify the code, there are linked folders in the j2ee projects, linked to each java project bin folders
For (4) I will probably have to use maven, but is it possible to fix problem (1) (2) and (3) without using maven ?
The alternative is to have a one page set up instruction document
Also do you have any other general or specific advices as to how organize this whole mess.
Thank you
Dependency management is a must - use Maven. If you can't use maven, because you are already using ant, go with Ivy.
Make the project buildable with one click - be int ant build all or mvn package. Maven provides integration with the IDE (via the plugin).
Don't reply on IDE metadata. like .project and .classpath. You can still commit them to ease Eclipse users though, but don't restrict the IDE.
Provide build-on-save. Either using Eclipse WTP, or using the FilSync plugin (it sounds like a hack, but is pretty cool)
Use build profiles (maven provides them automatically) - to create different builds for different environments
It's not always possible to configure everything in your maven (or ant/ivy) scripts. For any additional actions, like installing app server - document then in a single file in the root of your project, describing step by step what should be installed, with what config options, etc. Thus the developers have only one place to look at and follow. The document can (and better) be plain .txt
A sidenote: use Continous Integration - download Hudson or TeamCity and configure it to build a project
From my very recent experience - we had a project we've been working on for 6 months. A colleague of mine had to re-import the project on a new machine. It took him 20 minutes. The project is configured with Maven.
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).
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.