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.
Related
I am trying to build an EAR file - Which can be deployed in IBM websphere server.
This is an existing struts appliation, i am trying to mavenize it.
This project contains two folders
1. web
2. webEAR
web is actually for war file and webEAR folder for the EAR file, web contains all the code, and webEAR is a kind of a wrapper.
Steps I have already done are below
IDE - Eclipse
Java version - 1.7
Convereted both web and webEAR to Maven - (Configure to Maven)
edited the POM.XML like below
<modelVersion>4.0.0</modelVersion>
<groupId>com.comp.web</groupId>
<artifactId>web</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>WEB</name>
<description>WEB</description>
added all relevant jar files - which are in lib folder as below (sample)
<dependency>
<groupId>jarfile</groupId>
<artifactId>com.ibm.jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEBINF/lib/com.ibm.jarfile.jar</systemPat>
</dependency>
Now i dont have any errors in the eclipse, and I can run the application by right clicking the webEAR folder -> Run in Server, It works.
but I am not sure, how to create a EAR file , which has the war file, so that I can deploy in the WAS server dev environment.
Can someone show me a way I can do this. currently there is no POM.xml in the webEAR maven folder
P.S - I am not a Java developer. This is a first maven related project I am assigned to. I appreciate any help
Your module should have <packaging>ear</packaging>.
In the dependencies for this ear module ( Use a new module to build the ear ) include your war module as below.
<dependency>
<groupId>com.comp.webGroupId</groupId>
<artifactId>war-artifact</artifactId>
<version> war-version</version>
<type>war</type>
</dependency>
In the build plugins for this ear module include the maven-ear-plugin.
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<finalName>web</finalName>
<version>versionNumber</version>
<generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>com.comp.webGroupId</groupId>
<artifactId>war-artifact</artifactId>
<uri>web.war</uri>
<bundleFileName>web.war</bundleFileName>
<contextRoot>/applicationName</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
Add any specific configuration values as required.
I have a question regarding maven and its tomcat7 plugin :)
I have the following maven projects:
plugin1: plain java project packaged as jar
plugin2: plain java project packaged as jar
webapp: standalone webapp project packaged as jar
those three project are properly build in maven and the outcome works fine:
I can use the jars from plugin1/plugin2
I can deploy the webapp war file to a web container
I can run tomcat7:run to start the webapp
Now, I need to provide different packaging of the webapp containing specific plugin setup.
i.e. I want to generate a war file with webapp + plugin1 and another one with webapp + pugin2
To achieve this, I have created 2 additionnal maven projects that declare dependancies on the webapp project + the appropriate plugin projects and are packaged as wars.
The generated war files have the expected content, and can be deployed to a tomcat, but when I try to use the maven tomcat plugin (tomcat7:run again), it simply doesnt start anything.
Though this is not blocking for me (my main point was to generate the war files), I have the feeling that I missed something.
the pom.xml for those aggregate projects looks like this (note that there is absolutly no code in those projects, these were just created for packaging with specific dependancies convenience).
<groupId>my.project</groupId>
<artifactId>live1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>MyWebapp</name>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>my.project</groupId>
<artifactId>plugin1</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>MyWebapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager</url>
<server>localhost</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
Thanks !
note: long time lurker, first time asker here, if some information is missing tell me :)
Depending on the structure of your project it may not be suficient to just add a dependency of type war. You may need also to configure <overlays> as described here maven-war-plugin.
It looks like your final war does not provide the full web configuration that you expect. With overlays you can configure how the resources from the dependency will be packed into your final web app.
There must be some difference in the way that your external tomcat starts the app compared to the tomcat7 plugin. May be you can try -X option :
mvn -X tomcat7:run
This should log out some details, of what the embedded tomcat is configuring..
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
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.