eclipse m2e default plugins settings - eclipse

Env:
Eclipse (mars)
JDK 8
Wildfly 8.2.0 Final
Issue: Everytime i create a maven project
it uses JDK 5 (war and jar)
complains that web.xml is missing (in case of war).
So, everytime i have to
Open the pom.xml and include the plugin configuration in pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Change eclipse project compiler settings to use 1.8
Change JRE to use 1.8
Manually update maven project settings
This is a real frustrating thing to do. Tried to
find a solution in stackoverflow and google. Somewhat closer solution is here. It works but is not enough for me.
find any settings in eclipse but to no avail
find any xml file settings in eclipse m2e plugins but got nowhere
Would be very greatful if someone
point me if i am missing some settings
can offer any solution to this pestering issue.
Please note that i am able to resolve the issues (eclipse errors and m2e errors) but looking for a smarter solution to avoid menial work every time!
Thanks in advance,
Rakesh

The default settings you see come from default maven plugin settings.
The maven-compiler-plugin targets java 1.5
the maven-war-plugin has failOnMissingWarXml=true by default
The goal for m2e is to stay as close as what an actual Maven CLI build would produce. So if you want your project to build in command line or a CI server, you need to have these maven plugin settings.
In your workflow, you actually don't need to do steps #2 and #3. Executing Maven > Update project configuration (or Ctr+Alt+F5), will take care of that. You can also enable Automatic Project configuration update in Preferences > Maven (since m2e 1.6), so all you have to do is do your pom changes and save the file.
If you want to have more control on these maven settings during project creation however, you have 2 options:
Make your new Maven project inherit a parent pom, which has the maven-compiler-plugin and maven-war-plugin settings you want
Instead of creating a new Maven project, create a new Dynamic Web Project first. You can change the default Java and Web Facets in that Eclipse wizard Then change the default src folder to src/main/java, and change the default WebContent folder to src/main/webapp. Once the project is created, you can convert it to a Maven project (Right-click on project, Configure > Convert to Maven...). Give it the appropriate project coordinate, and when you hit finish, the generated Maven pom.xml will get maven plugin settings mapped to the original Eclipse settings.
A third solution would be to create a project from an existing Maven archetype. You can try wildfly-javaee7-webapp-blank-archetype, from the Maven Central catalog, to create a JavaEE 7 web project for instance ( (http://search.maven.org/#artifactdetails%7Corg.wildfly.archetype%7Cwildfly-javaee7-webapp-blank-archetype%7C8.2.0.Final%7Cmaven-archetype). Using JBDS or JBoss Tools Maven integration (http://tools.jboss.org) you'll have access to the Maven Central Archetype catalog by default. Else, you can add it yourself in Preferences > Maven > Archetypes > Add Remote Catalog... Use http://repo1.maven.org/maven2/ for the catalog file, and whatever description you like.

Related

How to run a spring web app without a full Tomcat install?

I just began learning Spring MVC, using this tutorial.
Entire write and build (under Eclipse) went successfully and a target .war file is generated.
However, I need to test-run it and I do not wish to download and install Tomcat at the moment.
I have heard there is a way to run it from within Eclipse without requiring a full-fledged Tomcat installation. How do I do that?
Add to your pom.xml the tomcat-plugin:
`
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
`
In Eclipse, add a debug/run configuration for Maven Build:
Right-click New, and in that new configuration's Goals enter:
clean install tomcat7:run
Now run that configuration (right-click pom.xml > Run as > Run configuration)

Tomcat returns 404 for webapp within Eclipse

i am using Eclipse Mars (4.5.2) and i installed Tomcat 8 as web server, and tried to run a Spring application on it. First, Tomcat management page did not load, but after i 'switched location' and now it shows the application on management site, but if i click on it, it returns 404. If i manually copy the war file, it runs, also if i run with
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/dcollect</path>
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
<warFile>${project.build.directory}/dcollect.war</warFile>
<username>admin</username>
<password>admin</password>
</configuration>
</plugin>
whitin maven, it also works just fine.
But if i run with 'Run on server', it shows the app on the list, but returns 404:
It turns out eclipse didn't export maven dependencies deploying the proyect. While packaging first to WAR it did include that. I had to do "proyect properties -> deployment assembly -> add java build path entries -> maven dependencies".
I can not explain why eclipse did not include that automatically, while importing other maven proyects from github for example it does.

setup maven project for java ee 7 (full profile) with eclipse (kepler-ee) and git

So, now I have access to empty git repository (project development to start soon).
Eclipse is chosen IDE and maven as build tool, Glasshfish 4 as application server.
I have no problem using git via command line, outside eclipse, but it would be nice having complete setup within eclipse.
By the way, I've never used maven before, or Java EE, but I'm currently learning concepts and specs for javaEE platform.
Thanks
You can use EGit (an Eclipse Git plugin) as a complement for the most common tasks. I used it a few years ago, had some issues, but the guys developed it quite actively so it should be mature for now.
As for Maven + Glassfish, I'd recommend reading a few tutorials like Maven in 5 minutes and this for setting up the devenv. Believe me, there are tons of tutorials out there.
well, here is what I have done in the end. Hope this is useful to someone else
Following this tutorial I've created maven directory structure for full Java EE 7 project (used java ee7 archetypes instead ee5 where applicable).
In root pom.xml I've added
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
so all modules will depend on java7.
I've copied this to git root folder, added .gitignore file for eclipse files.
In Eclipse, I've used import maven project. After that, right-click root project (eclipse will create multiple projects) folder and Team > Share Project > local git.
I guess only thing remaining for other devs beside import maven project after initial git pull (outside eclipse), is to configure java ee application server (Window > Preferences > Servers > Runtime Environments)

In eclipse how to add existing maven project as web project

i am trying to run maven project as dynamic web projects.
I have my maven project in my eclipse. i want to run project on localhost:8080/abc like this.
Please suggest me the settings.
Well, I dont know if this is what you are looking for, but if you just want to run your Maven Web project easily, you can use the jetty-plugin to run it.
The configuration would be:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.3.v20120416</version>
<configuration>
<webAppConfig>
<contextPath>/abc</contextPath>
</webAppConfig>
</configuration>
</plugin>
Firstly, your maven project should be a web project (<packaging> should be war for instance).
You should have Eclipse IDE for Java EE Developers.
You should configure a server in your Eclipse - say tomcat, jetty, etc.
Install m2e Eclipse plugin as well as m2e-wtp support plugin.
Import maven project to Eclipse. After it build you should be able to choose "Run as server..." option and specify the server you have configured.

From Eclipse, how can I run my Maven project in Tomcat?

I'm on Windows XP, using Eclipse Indigo, Tomcat 6.0.33, and have the Maven plugin installed. (Using Maven 3.0.3 on my system). I have Tomcat showing up in my Eclipse servers list, but I can't figure out a one click way to deploy my WAR project to the Tomcat server. When I right click my project and select "Run" there are many Maven options (e.g. "Maven Install"), but none builds and then deploys my project to Tomcat.
Any help along these lines? Thanks, - Dave
see below link for details
http://mojo.codehaus.org/tomcat-maven-plugin/deployment.html
Alternatively, search for tomcat:run and you can use it directly
EDIT:
Run/Debug Configurations
Double click maven build, a new configuration will be created
put ${project_loc} for base directory
put tomcat:run for goals
give an appropriate name for yourself at the top
Apply and run/debug using your new configuration
EDIT2:
The link has been changed to below one:
http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/
(Thanks #Lucky)
within Eclipse, you can run the project by doing the following:
In the servers view, create a server (right-click, new Server, Tomcat)
Add the project to the server (right-click the server, add & remove, select the project)
Start the server - the server will start & deploy the app
The trick to this is that the server does not deploy the packaged app in the tomcat webapps directory, it deploys an exploded version into a directory under the plug-ins directory of the eclipse installation.
To specifically do the maven packaging and deploy to the external tomcat istance (external to eclipse), use the tomcat-maven-plugin, as specified by fmucar
Run Configurations : Select Base Directory of our maven base project directory.
Give Goals as tomcat7:run to run application and tomcat7:deploy for deploy tomcat7:deploy
In maven settings.xml, give server configuration as below under <servers> tag
<servers>
<server>
<id>TomcatServer</id>
<username>admin</username>
<password>admin</password>
</server>
<servers>
In the parameters section of run configurations give parameter maven.tomcat.port and give any required port number. Ex: 7777
In the pom.xml provide tomcat plugin as below under <build> tag
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:7777/manager/html</url>
<server>TomcatServer</server>
<username>admin</username>
<password>admin</password>
</configuration>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>run</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<port>7777</port>
</configuration>
</execution>
</executions>
</plugin>
within Eclipse, you can run the project by doing the following:
In the servers view, create a server (right-click, new Server, Tomcat) Add the project to the server (right-click the server, add & remove, select the project) Start the server - the server will start & deploy the app
The trick to this is that the server does not deploy the packaged app in the tomcat webapps directory, it deploys an exploded version into a directory under the plug-ins directory of the eclipse installation.
To specifically do the maven packaging and deploy to the external tomcat istance (external to eclipse), use the tomcat-maven-plugin, as specified by fmucar
This I do not get because I don not want to add any maven plugin, I wanted to run it in simple manner like in old plain servlet programs we used to add server in server panel of eclipse and then over project we used to do Right Click and run on server.
Here how can I do it without adding maven plugin or please explain in details why maven plugin explicitly needed why I can not run server added to eclipse. I did steps given above(last solutions) but in that case server added to my eclipse do not starts instead of that server which was downloaded during maven plugin resolution (I am talking about tomcat:run command) process gets started.
Please explain in details as short answers only confuses I am beginner for maven.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
As Simple as that, just add above build tag under project tag in pom.xml and run by giving tomcat:run goal command in maven run configuration in eclipse.