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.
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)
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.
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.
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.
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"