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.
Related
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)
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.
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)
I'm using M2E to create Maven archetype projects (in this case a simple web app) with the aim of using Maven to deploy to a remote tomcat server.
I've added the tomcat-maven-plugin to the POM.XML file, and it appears to be correct.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>localServer</server>
</configuration>
</plugin>
and when I type "mvn tomcat:deploy" into terminal it deploys successfully. So I know my settings.xml as well as my tomcat settings are in order.
Is it possible to deploy the application directly from Eclipse without having to go through the terminal. In other words is it possible to pass the command "mvn tomcat:deploy" from eclipse to maven?
Cheers
You can run all maven goal directly from Eclipse Run Configurations
http://mevenide.codehaus.org/mevenide-ui-eclipse/user-guide/run.html
Also you can configure Server View in Eclipse (WTP) and simply deploy (or auto deploy after file change) directly from eclipse (maven is not used in this process, he is only responsible for configure proper nature of your project - ex. war).
Maven Integration for Eclipse WTP (a.k.a m2e-wtp) aims at providing a
tight integration between Maven Integration for Eclipse (a.k.a m2e)
and the Eclipse Web Tools Project (WTP) .
m2e-wtp provides a set of m2e connectors used for the configuration of
Java EE projects in WTP. It features :
Support for war projects : adds the Java and Dynamic Web Facets.
Support war overlays and on-the-fly resource filtering
Read also this: Maven/Tomcat Projects In Eclipse Indigo/3.7
I have created a Spring 3 + Hibernate project using Maven in Eclipse. How can I deploy my project to a Tomcat server using Maven.
Help is highly appreciated.
If you add the Tomcat Maven plugin, all you have to do is
mvn tomcat:deploy
(after adding the server to your Maven configuration)
Adding to what #Sean Patrick Floyd and #Michael Borgwardt had already suggested, If you are using Eclipse, you can also follow this to generate your .war file.
I assume the project is Maven enabled, Else:
Right click on your project -> Select Maven -> Select Enable Dependency Management.
To generate the .war:
Right click on your project -> Select Run As -> Select Maven Package.
This will generate a war file into target directory located in your project.
To deploy to Tomcat:
Copy the generated war file to your webapps directory in Tomcat.
Easy enough:
On the command line, run
mvn clean install
or
mvn clean package
Upload the resulting war file to Tomcat via the Tomcat Manager Interface.
You'll find the war file at ${basedir}/target/${artifactId}-${version}.war
Use tomcat maven plugin:
http://tomcat.apache.org/maven-plugin.html
I am not sure what you exactly want to do. If you want to do some integration tests, and need therefore to deploy the project in the server, you can also use maven cargo.
I agree with Michael, you should using Tomcat Maven plugin
First, adding those configures in you pom.xml:
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<configuration>
<server>local_tomcat</server>
<url>http://hostname:port/manager/html</url>
<username>user</username>
<password>password</password>
</configuration>
</plugin>
...
</plugins>
Then, you can deploy your web site with one maven command:
mvn tomcat7:deploy
If you need to undeploy the old deployment first, you can using :
http://user:password#hostname:port/manager/text/undeploy?path=/your-web-site-path
There is slight difference if you are using old version tomcat. You should refer Tomcat Maven plugin doc.
You could also use Apache Cargo, which is more general than the Tomcat Maven plugin.
Here is an answer to a related question:
https://stackoverflow.com/a/10936575/1017787
You can create war file of project using maven. Then you can deploy it in the webapps folder of your tomcat.
You must be edit server.xml in your workspace:
<Server>
<Service>
<Engine>
<Host>
<Context path="/<myproject>" docBase="<myproject>">
<Resources className="org.apache.naming.resources.VirtualDirContext"
extraResourcePaths="/../<workspace>/<myproject>/src/main/webapp" />
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
virtualClasspath="/../<workspace>/<myproject>/target/classes;/Users/<myuser>/.m2/repository/log4j/log4j/1.2.15/log4j-1.2.15.jar" />
<JarScanner scanAllDirectories="true" />
</Context>
</Host>
</Engine>
</Service>
Because, the project structure generate by maven is different. It work with appfuse web application. Also you must be run "mvn tomcat7:deploy"