vks
vks

Reputation: 7071

Deploy Maven project with Spring+Hibernate to Tomcat

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.

Upvotes: 8

Views: 9886

Answers (9)

Marcos
Marcos

Reputation: 1

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"

Upvotes: 0

Michael Borgwardt
Michael Borgwardt

Reputation: 346310

If you add the Tomcat Maven plugin, all you have to do is

mvn tomcat:deploy

(after adding the server to your Maven configuration)

Upvotes: 8

code_fish
code_fish

Reputation: 3428

You can create war file of project using maven. Then you can deploy it in the webapps folder of your tomcat.

Upvotes: 0

JBCP
JBCP

Reputation: 13485

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

Upvotes: 0

hao
hao

Reputation: 1214

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.

Upvotes: 0

user897493
user897493

Reputation: 251

Use tomcat maven plugin:

http://tomcat.apache.org/maven-plugin.html

Upvotes: 1

Ralph
Ralph

Reputation: 120791

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.

Upvotes: 0

Bitmap
Bitmap

Reputation: 12538

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.

Upvotes: 5

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298898

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

Upvotes: 1

Related Questions