There is an Eclipse Plugin managed by Maven containing this configuration:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>wonttellya</groupId>
<artifactId>wonttellya</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
...
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.10</version>
<configuration>
<pde>true</pde>
</configuration>
</plugin>
</plugins>
</build>
</project>
In console I run
C:\Users\user\git\wonttellya\mvn
eclipse:eclipse -Declipse.workspace=C:\Users\user\workspace2
...
Using Eclipse Workspace: C:\Users\user\workspace2
...
BUILD SUCCESS
If I open Eclipse in the workspace there is no project.
First of all, you have to understand that the purpose of the maven-eclipse-plugin is, quoting its documentation:
to generate Eclipse IDE files (*.classpath, *.project, *.wtpmodules and the .settings folder) for use with a project.
Its goal is not to create an entire project but the building Eclipse blocks from an existing project.
This is also true for PDE support. Quoting its documentation:
Note that the scope of the maven-eclipse-plugin is to synchronise the Eclipse .project and .classpath files with the configuration found in the pom file. Once you have finished configuring the Eclipse plugin as below, and once you have run the eclipse:eclipse goal, you will be in a position to build your plugin code with the Eclipse IDE, or the Eclipse headless PDE build. The Eclipse headless PDE build can be triggered from within Maven using the pde-maven-plugin.
As such, the configuration you have simply enables the creation of correct .project and .classpath files for an existing project, nothing more. Once this configuration has been made and eclipse:eclipse goal was run, you will need to follow these steps:
Open Eclipse and import the existing project, by going to "File > Import... > Existing Projects into Workspace".
Right-click the new project and select "Configure > Convert to Plugins Projects...". Confirm this choice.
You will then be able to build your Eclipse plugin directly in the IDE.
Note that I do not recommend using this solution and I would suggest you use Tycho instead, this might be an improvement you could make to this plugin (refer to this question).
Make sure you have update your project before you run the maven install
Try to click on your project with the right mouse button and go to maven-->update project
For a different clause
You can use export and import with archive (.zip) that you can manage Plugin and simply transfert your project in different workspaces
Related
I am wondering if there is a way to dynamically deploy a maven project on eclipse and have the same result as if it was packaged in a WAR.
I noticed that when I right-click the project and choose "run as" and then choose tomcat the project deployed does not work properly but when I generate the war and place it manually it works fine.
That means everytime I change something in the code I have to generate a war and deploy it manually on the server.
Is there a tomcat config that I can use to have an output when I run from eclipse similar to when i generate a war?
I'm using tomcat 6.0.26 and eclipse Neon 3.
Thanks.
Yes, you can ...
In general the steps are:
1) Turn your existing project into a maven project by adding a pom.xml like this into the project root folder:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany</groupId>
<artifactId>yourApp</artifactId>
<packaging>war</packaging>
<version>2.3</version>
<name>Your Web Application</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Add your dependencies as needed. -->
</dependencies>
</project>
2) Rightclick the project and Configure -> Convert to Maven Project
3) In Eclipse Servers view add an Apache Tomcat.
4) Rightclick the Tomcat server and Add and Remove ... -> Add your project.
5) Launch the Tomcat in debug mode.
Now eclipse will deploy the project in exploded .WAR format, replacing and therefore hot deploying resources on every change and compiling Java classes on change.
If you do not alter Java method or class signature, changes in Java source code and resources take effect instantly without the requirement to restart Tomcat or the web application.
The problem was that I didn't configure the maven profiles when I ran the project from eclipse which explains why I had different outputs when deploying the project from a war and directly from eclipse. The answer here Maven Profiles and Tomcat in Eclipse explains how to configure maven profiles when you run on server from eclipse.
I've just started a java project, in which I'd like to use the classes of another project.
My pom.xml looks like this so far:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
What would be a good way to add that other project as a dependency in mine? Should I download all of its compiled jar files and add them one by one in my pom.xml as dependencies? Or is there a better option?
I was thinking of downloading all the jars, putting them into a directory (e.g. lib) and somehow referencing that entire directory in the pom.xml, so if there's a new version of the project mine depends on, I only have to change the contents of that lib folder for the new jars, and don't have to edit the pom.xml. Is it an option? If so, how to do that?
Or most importantly, what is the proper way you suggest doing it?
If you want to use the latest version of this project, I suggest you build it yourself. Because it seems they are releasing to Sourceforge and maintaining the code actively.
Each time you want to upgrade the version, you have to get the latest source code (via git) and use mvn install command on this projects root pom.xml to install it to your local maven repo. This project is configured as multi module maven project, using install on the root pom.xml will install all the sub modules.
On your projects pom.xml you can use mvn versions:use-latest-releases to update all your dependencies to the newest version. This command will automatically upgrade dependency versions for you.
To add a project as dependency follow Marvins link.
I want to create a web application project in Eclipse with Maven. Everytime I try to create the project I get an error as "Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories".
I have checked for solutions presented in other questions tried them, but none of them solved the issue. I have also changed my settings.xml file to point it to proxy even that didn't help. I also tried deleting the repositries folder in .m2.
Please suggest some solutions for this
Open Window > Preferences
Open Maven > Archetypes
Click 'Add Remote Catalog' and add the following:
Catalog File: http://repo1.maven.org/maven2/archetype-catalog.xml
Description: maven catalog
That is quite a weird issue ... however m2eclipse gave me my fair share of problems when I tried to create my projects. In fact, I ended up creating the archetypes myself!
Let me share my maven 3 POM file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- add your dependencies here -->
</dependencies>
<build>
<finalName>example-project</finalName>
<pluginManagement>
<plugins>
<!-- v. useful! m2eclipse sometimes fails to see it as a
dynamic web app project in Eclipse. Declaring this plugin
would help eclipse recognize its nature (i.e. a Java
project requesting at least JDK1.7+ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Running mvn eclipse:eclipse on this project should work. You can safely import to eclipse as a maven project as well (File > Import > Existing Maven Projects) If it doesn't, then you should consider re-installing a fresh copy of maven.
Let me know if you manage to get it up and running. :)
I was recently struggling to create a new Maven project in Eclipse. Trying to create a Dynamic Web Project first and then converting it into a Maven project did not work (none of the Java integration was working and my code wouldn't even compile)!
The following article describes how to create a Maven project in Eclipse.
The tutorial recommends skipping the archetype part, which might solve the issue described in the original question:
https://www.tech-recipes.com/rx/39279/create-a-new-maven-project-in-eclipse/
If that doesn't work for you, perhaps doing a clean install with the latest version of Eclipse, in a new directory, may help. What you described might just be a bug in Eclipse or one of its installed plugins.
What's the correct form to set up a maven webapp project?
It should be able to:
Run with the eclipse embedded tomcat (available in the servers tab).
This way I can run/debug the application like a regular webapp.
Run with the maven plugin tomcat7. So far I can only run the run-war
goal, couldnt make the "run" goal work =/
I have followed some tutorials, but couldnt make all these things to work properly.
When I follow the MkYong suggestion, I can run with the embedded tomcat, but the project dependencies are changed to classpath variables. This is not a good consequence at all, since the project loses the ability to dynamically set the dependencies.
I use Eclipse Juno (I'd rather wait Kepler for a couple of months to check it is really stable), m2e and m2e-wtp plugins, and have 2 kinds of projects: one is based in JSF (the front-end) and another in Apache CXF (the back-end). I hope these two can be hot deployed (when a resource changes, embedded tomcat automatically publishes it) in development environment to improve productivity.
Source taken from
Web applications created by the Eclipse IDE contains an annoying folder WebContent to host the web resources and deployment descriptors. Quite natural for Eclipse users, this feature ignores the Maven convention and force the developers to hack the pom files in order to get the project up and running in Eclipse. In this aspect, Eclipse if far behind the other IDEs regarding Maven support, even if you consider the very good M2Eclipse plugin. So, for you lazy Christmas hackers, here it is a solution for the Maven integration problems in Eclipse based on the maven-war-plugin.
ERRATA: please use the WTP plugin instead of changing the project structure. I figured out the wtp plugin after writting this blog, so I suggest you to check just the 1st and the 3th steps of the below instructions. I kept the original blog information in case you really need or want to change the project structure.
Create a Web Project in Eclipse: right-click on the Project Explorer
New > Project > Web \ Dynamic Web Project
Create a pom.xml file in the project root folder, with the following
content:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.cejug</groupId>
<artifactId>webapp-test</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>webapp-test Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<build>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/WebContent</directory>
</resource>
</webResources>
<warSourceDirectory>WebContent</warSourceDirectory>
<warSourceExcludes>WebContent/WEB-INF/lib/*.jar</warSourceExcludes>
<archiveClasses>false</archiveClasses>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix />
</manifest>
<manifestEntries>
<url>${pom.url}</url>
<Implementation-Build>${buildNumber}</Implementation-Build>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Vendor>CEJUG</Implementation-Vendor>
<Implementation-Version>${project.version}</Implementation-Version>
<Built-By>${user.name}</Built-By>
<Built-OS>${os.name}</Built-OS>
<Build-Date>${timestamp}</Build-Date>
<SCM>${buildNumber}</SCM>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Compile and prepare the project for eclipse:
mvn -Dwtpversion=2.0 compile eclipse:eclipse
Notice the usage of the plugin -Dwtpversion to enable Maven to add Eclipse WTP Support to the project. That simple flag do the trick :). Actually just using that flag will work, but not all plugins of Eclipse will work out of the box without the WebContent folder - it is up to you to decide if it is worthy to modify your project structure or just go straight ahead with the plain Maven folder.
Done, now you can refresh the project in Eclipse and continue to work. Remember that jjust the resources folder is hard coded in Eclipse, the src/main/java continues as Maven expects. Perhaps some day we can have the confluence between the conventions of Maven and Eclipse and then we will finally becomes free of this daily basis hacks.
We are using Kepler and we find it quite stable. You can create a normal Dynamic Web Project and then right click and make the project Maven enable. Then you have hot deploy and maven management POM.
Also you can have all Maven goals there.
I created a web project with maven like this:
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
Then I run mvn eclipse:eclipse so that an eclipse project is built. Eclipse recognizes all the features of the project but it doesn't recognize it as a web project.
Therefore, when I create a server inside my eclipse workspace, and go to the dialog where I select what projects to deploy to my server, I am not offered to deploy my newly created project.
Ideas?
You should explicitly mention in your pom.xml that the maven-eclipse-plugin should generate a WTP-project. A simple example, which should be in your pom.xml at the build-part, would be:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
</plugins>
You can also use mvn eclipse:eclipse -Dwtpversion=2.0 to generate all WTP meta-data for the project without changing the POM.
Of course, you'd have to change the WTP version if you are using an older version of Eclipse.
Just install a development version of m2eclipse and your project will be used as a maven project, no need to do mvn eclipse:eclipse or anything like that. I use it and works.
http://m2eclipse.sonatype.org/
Did you jump from the create command to the eclipse:eclipse command?
Check out this link. You need to edit your POM first, then call "mvn clean package". After you do that, THEN try the "mvn eclipse:eclipse".