How to generate pom file for existing eclipse plugin project? - eclipse

I didn't really use maven so it may be noob question.
I have Eclipse plugin project and before I deploy it, I need to generate a pom file. The regular pom file is designed for java projects and if I try to generate from them I lose my plugin dependencies. Is there a way for maven to include them,too ?

Converting a standard Eclipse plugin project to a Maven structured project is not as simple as generating a pom file. The project needs to be in the same directory structure that Maven expects.
If you want to build Eclipse plugins as Maven projects take a look at Tycho (http://www.eclipse.org/tycho/).

Related

Using maven generated sources in Eclipse

I have an application made up of a number of maven projects. I work on it in Eclipse. Some of the projects use Maven plugins to generate stub classes for web services etc.
When i import the projects into a new workspace I have to issue a maven generate sources command followed by attach source folders to build path on each project. The application i work on has more than 5-6 projects which require these steps.
Is there a plugin I can install in Eclipse to pick up the generated sources, or even one that generates the sources and updates the build path to save the manual steps?
I'm pretty sure the m2e plugin takes care of this automatically. m2e is included in the primary Java and Java EE packages of recent Eclipse versions, so you probably already have it. If you right-click on your project, and there is a Maven submenu, then the project is already managed by m2e. Otherwise, right-click and choose Configure > Convert to Maven project.
Well, it depends on exact maven plugin you are using.
generate sources
Before I considered that m2e connector would be needed for any non common plugin, like generator. But I came recently on some plugins (1), that do it without special m2e connector.
attach source folders to build path
For this part check build-helper-maven-plugin and answer to M2E and having maven generated source folders as eclipse source folders

How eclipse maven and ant work together?

I made simple maven project and I opened it with Eclipse. I have installed maven plugin for Eclipse. I'm interested in following:
How Eclipse compiles code when I hit save on my source code (does it use configuration from ant or maven or something else)?
When I run tests from JUnit plugin for Eclipse those Eclipse calls mvn test (I suppose not, but what is then happening exactly)?
Is it possible that maven does the build successfully but Eclipse is
showing errors in code?
The Maven Integration for Eclipse makes it easier to edit POM files, allows you to execute maven builds from within Eclipse and to help with dependency management. It doesn't actually compile your code (unless of course you execute a maven build from within Eclipse). The main help is with the dependency management and writing the .classpath file of your project within Eclipse.
To try and answer your questions:
Eclipse uses its standard mechanism to compile code. With a standard eclipse for java developers your project will have a Java Project nature and Eclipse will then use the Java Development Tools - JDT to compile the code. (Internally this uses an incremental builder to build the code http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_builders.htm). What source files it will compile and where it will place the resultant .class files is configured in your project's Java Build Path (which I am guessing the maven plugin may well configure for you)
JUnit support is part of the Java Development Tools as well.
It is possible that maven will successfully build a project outside of Eclipse, but that the same project will show errors within Eclipse. This is usually down to classpath errors (dependencies defined in the project's POM not being added to the classpath in Eclipse). If you are using the maven plugin with eclipse this probably shouldn't happen. If you are not using the maven plugin within eclipse you can execute maven eclipse:eclipse to have maven update the Eclipse .classpath file of the project which should then fix any of these problems.

Can Maven3 play nicely with non-Maven projects in Netbeans?

I have a project that depends on a library that is only easily available through Maven (OpenIMAJ). I have set up a Maven 3 project in NetBeans 7, and can develop my code that way. I would like to integrate the build product from this Maven project into a larger NetBeans project that does not use Maven 3. What's the smoothest way to get the JAR output from the Maven build process into my Netbeans (non-Maven) project, with the proper dependencies in the classpath?
Build & install Maven-project to local Maven repository (Or deploy to shared repository)
In non-Maven-project, express a dependency on the JAR (?) built by Maven-project just like you would for any other JAR

Generate Web Application Project for Eclipse using Maven.

I'm new to this approach. I've used Maven, Tomcat and Eclipse for my web application. But I'm trying the approach where you create a Maven project using an archetype plugin.
My goal is to create a Web Application Project for Eclipse using Maven that can then be imported into Eclipse. I'm pretty sure there is a super-easy way to do this and I want to know what it is.
I'm using Tomcat 6, Eclipse Helios and Maven 2.
I was referring to this 3-part post:
http://united-coders.com/phillip-steffensen/maven-2-part-1-setting-up-a-simple-apache-maven-2-project
But when I imported the project into Eclipse, I couldn't see the Run As > Run on server option.
What is the best way to go about this? Any links to resources that'd help me understand the approach would be great!
My goal is to create a Web Application Project for eclipse using maven that can then be imported into Eclipse. I'm pretty sure there is a super-easy way to do this and I want to know what it is.
Use the maven archetype plugin to generate your project. Here is how to tell it to use the maven-archetype-webapp when invoking it from the command line:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
But when I imported the project into eclipse, I couldn't see the Run As > Run on server option.
It actually all depends on what you use for Eclipse/Maven integration. There are basically two options (and they both provide WTP integration):
the maven-eclipse-plugin which is a Maven plugin that can generate Eclipse files (.project and .classpath and so on) allowing to import the project as Existing projects into Workspace.
the m2eclipse plugin which is an Eclipse Plugin providing Maven integration inside Eclipse and allowing to import a Maven project as Existing Maven projects.
The maven-eclipse-plugin approach
If you use the maven-eclipse-plugin, you have to configure it for WTP support and here is a typical configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
<manifest>${basedir}/src/main/resources/META-INF/MANIFEST.MF</manifest>
</configuration>
</plugin>
With this configuration, running mvn eclipse:eclipse on your maven project will generate the WTP files so that the project can be recognized as a Dynamic project (i.e. runnable on a Server). Then import it via Import... > Existing projects into Workspace.
The m2eclipse approach
If you use the m2eclipse plugin (and that would be my recommendation), make sure to install the Maven Integration for WTP from the extras. From the install instructions:
Installing m2eclipse Extras
To install optional m2eclipse
components, you will need to use the
m2eclipse Extras update site. This
update site contains the following
m2eclipse components:
Maven SCM Integration
Maven SCM handler for Team/CVS
Maven SCM handler for Subclipse
Maven issue tracking configurator for Mylyn 3.x
Maven Integration for WTP
M2Eclipse Extensions Development Support
m2eclipse Extras Update Site: http://m2eclipse.sonatype.org/sites/m2e-extras
And then just import your project via Import... > Existing Maven projects and if it's a webapp, it should get recognized as a Dynamic project.
Indigo: m2eclipse approach for Indigo is different. See Maven/Tomcat Projects In Eclipse Indigo/3.7
Important: Note that both approaches are exclusive, use one or the other. But in both cases, there is no need to add a facet manually if you use them correctly.
Download and install the eclipse maven plugin from here. Create your project using the new project wizard in eclipse. Select Maven project and create the project using the archetype you discussed. Set appropriate source folders and add libraries used as part of project properties. This should set you up for your project.
Very simple,
you only have to create a new Maven project with packaging type ‘war’ and directories creation done automatically

Eclipse+Maven compile problem

currently, I am developing web-apps using Eclipse.
The build is done using Maven.
The problem is that during compile time Eclipse is showing a lot of errors since there are a lot of missing jars. The final result is OK since the Maven is responsible for fetching these jars.
How can make the eclipse not fail the compilation?
I know I can just add the missing jars to the project classpath, but that's not what I'm looking for because I have a lot of projects, and the .classpath file of each project is a file common to all developers, so I would rather not to change it.
My question is therefor, is there a way to add a common classpath to all Eclipse projects without changing each project's classpath?
I use m2eclipse. It adds a classpath container to the .classpath file. This container is populated with the Maven dependencies by a Maven builder (added to the .project when the Maven nature is enabled) which processes the POM and downloads any artifacts (and sources if needed).
To enable the Maven nature (assuming the plugin is installed), right-click on a project and select Enable Dependency Management.
By default m2eclipse uses an embedded version of Maven to do its processing. This typically means a separate local repository and duplicate files on the box. You can configure it to use your standard Maven installation in Window->Preferences->Maven->Installations. Then adding the path to your Maven installation (normally the same as M2_HOME).
There is another Maven plugin for Eclipse called IAM (formerly called Q4E). IAM is an Eclipse integration project and has some promising features - it's worth keeping an eye on.
There is a comparison of the Eclipse Maven integrations, alongside the maven-eclipse-plugin (a goal that generates the Eclipse metadata files from the POM contents). I personally find the maven-eclipse-plugin more trouble than it's worth but it may suit your purposes and it is handy for generating the initial metadata if you have none checked into the SCM.
Check out the m2eclipse plugin. It will read each project's POM and automatically fetch and add all dependencies to the classpath.