java java
java java

Reputation: 415

How can I deploy my Java files to my Tomcat Server automatically?

I have a web project in Eclipse which includes a Tomcat server. The Tomcat server is installed in Path C:\Program Data ... and my Workspace from Eclipse is in D:\Webproject.

Now if I have to edit my java servlet classes, I have to copy the class and JSP files from D:\Webproject to C:\Program Data\Tomcat\Webapps.... . This takes me a lot of time.

Is there any solution where the data is automatically deployed i.e. the edited classes and JSP are moved to my tomcat folder under C:.. ?

Upvotes: 6

Views: 12594

Answers (5)

Olivier Masseau
Olivier Masseau

Reputation: 854

Eclipse can do all that work for you.

To add the Tomcat server in eclipse:

  • Open the 'Servers' view by going in Window->Show view->Servers.
  • Do a right click in the 'Servers' view and select New->Server.
  • Select Apache\Tomcat vX.X Server (where X.X is your Tomcat version) and click Next.
  • Enter your Tomcat installation directory and click Finish.

To deploy your project to the server:

  • In the 'Servers' view, right click on the Tomcat server and choose 'Add and Remove...' and add your project, then press Finish.

You can then start/stop/debug/restart the server by right clicking on it.

When you modify a class/jsp it should be automatically deployed.

You can also force a republish of your project by right clicking on your project name after expanding the Tomcat server entry.

Double click on the Tomcat server entry if you need to modify the configuration of your server.

Upvotes: 6

nano_nano
nano_nano

Reputation: 12524

Ant is one possibility you have. Build your war-file and copy it automaticaly to your Tomcat directory. the tomcat will compile the sources via hot deploy. Here you get a nice documentation:

Ant War-File

and the copy task:

ant copy file

Upvotes: 0

Daniel Pokusa
Daniel Pokusa

Reputation: 336

Ant is a little bit oldschool.

Try Maven: http://maven.apache.org/

(maven-deploy plugin)

Or gradle (imho better option): http://www.gradle.org/ (gradle install task)

You can also configure autodeploy in eclipse when you add your tomcat plugin to eclipse servers.

Upvotes: 0

Konstantin Yovkov
Konstantin Yovkov

Reputation: 62874

In order to avoid copying all the stuff manually, you can create a Context for the Tomcat server, that points to the WEB-INF folder of the application.

Go to `$TOMCAT_HOME/

Go to $TOMCAT_HOME/conf/server.xml and add a context for where is the WEB-INF of the project located. For example:

<Context path="/Webproject" 
         docBase="D:/Webproject/WEB-INF" 
         reloadable="true" />

What does this mean ?

  1. The application will be accessible under http:// $tomcat-host:$tomcat-port>/Webproject.
  2. Tomcat will search for application to run under D:/Webproject/WEB-INF.
  3. Every time you change something on some of the jsp files or the web.xml, the application will be reloaded automatically in Tomcat. That's what the reloadable="true" stands for.

Upvotes: 0

Himanshu Bhardwaj
Himanshu Bhardwaj

Reputation: 4123

You can consider configuring the Tomcat server into eclipse only, and map the corresponding webapp with that tomcat. This will give you the advantage that mostly when you edit the file it will get automatically deployed or you just have to republish the changes with a right click.

For a head-start:

http://www.eclipse.org/webtools/jst/components/ws/M4/tutorials/InstallTomcat.html

http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

Upvotes: 0

Related Questions