Deploying a WAR in Tomcat / Eclipse

88,152

Solution 1

Tomcat behaves differently in development and production mode. When you develop your webapp in Eclipse there is no reason to deploy a WAR file of your application as a WAR during development.

Just go to the "servers" view and add a new server (you should already have done this otherwise you could not create your Dynamic Web project). In the server view you should see the server you created (Tomcat at localhost or something similar) just right click it and go to the Add and Remove section. Here you can add and remove the Dynamic Web projects you created in Eclipse. Once you added your project, all you have to do is click the green start button in the servers view and your app should be available in at localhost:8080/mycontext.

When you're done building your app just right click the project and go the the Export section in the menu. You should be able to export a WAR file. Once you have your WAR file you can upload and deploy that on a Tomcat instance that is NOT tied to Eclipse running in dev mode.

Solution 2

Yes, in a way, you can deploy a war in the dev mode.

I have the same problem.

I have an Eclipse webapp project, which Eclipse deploys to an instance of Tomcat run by Eclipse, so I can hot-edit the project.

This Web project needs to use resources published by another webapp that has to be run within the same instance of Tomcat. The other webapp is a completed project by someone else, so it is already in a war form.

I needed to File->Import the war as an Eclipse project and let Eclipse deploy it to the same instance of Eclipse, in order to run it in the same instance of Tomcat in which my webapp also runs.

The problem is that some wars work this way but some others do not, while all of them work perfectly fine in a stand-alone Tomcat (started by startup.sh). I can't figure out why.

Solution 3

This is old but is one of the first answers in google search.

You can import the war file:

A Web Archive (WAR) file is a portable, packaged Web application that you can import into your workspace.

Before importing a WAR file, you should first determine if the WAR file contains needed Java™ source files. When importing a WAR file into an existing Web project, the imported Web deployment descriptor files are either not changed or overwritten by the ones included in the imported WAR file, based on your response to the prompt that is provided. In either case, this action does not represent a merging of the two sets of deployment descriptors.

To import the Web project resources in a WAR file into your workspace, complete the following steps:

  1. Select File > Import .
  2. In the Import dialog, select WAR file and then click Next.
  3. Locate the WAR file that you want to import using the Browse button.
  4. The wizard assumes you want to create a new Web project with the same name as the WAR file. If you accept this choice, the project will be created with the same servlet version as specified by the WAR file and in the same location. If you want to override these settings, you can click New and specify your new settings in the Dynamic Web Project wizard.
  5. Click Finish to populate the Web project.

Source: http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Ftwimpwar.html

Solution 4

If all you have is a binary WAR (no source code), it cannot be installed within Eclipse. This can happen in certain scenarios outside of normal development workflows. Here's the work-around solution:

  1. Launch another instance of Tomcat (outside Eclipse).
  2. Modify the tomcat-users.xml file to enable admin
  3. Go to http://localhost:8080/manager/html
  4. Scroll down to WAR file to deploy
  5. Click Choose File (next to Select WAR file to upload) and click Deploy.
Share:
88,152
Loïc Guillois
Author by

Loïc Guillois

Updated on May 19, 2020

Comments

  • Loïc Guillois
    Loïc Guillois almost 4 years

    I use Tomcat 6.0 and Eclipse 3.0 under Linux and I try to deploy a WAR in Tomcat. The problem is that the server is managed by Eclipse and I have some Eclipse project deployed. I tried to modify the server.xml file then launch Tomcat via Eclipse but it doesn't work:

    Could not load the Tomcat server configuration at /Servers/Tomcat v6.0 Server at localhost-config. The configuration may be corrupt or incomplete.

    I tried to extract the war in the webapps directory but the webapp is still inaccessible.

    What is the best practice to deploy a War ?

  • Loïc Guillois
    Loïc Guillois over 13 years
    Ok. so I can't deploy a WAR on a Tomcat in dev mode. What a pity!
  • Luke
    Luke over 13 years
    @lgu: Maybe you can explain the reason you want to do that.
  • Loïc Guillois
    Loïc Guillois over 13 years
    Because I've built an application which provide a JSON API consumed by my "eclipse app". I encounter a cross domain exception by running the apps on different servers and I can't use jsonp. The solution is to use a local proxy (nginx...) but that's a bit overkill IMO
  • Luke
    Luke over 11 years
    When you run your application in development mode within Eclipse, the deployment happens automatically when you "run" the application. Deployment is only something you need to do for a testing or production server.
  • JohnEye
    JohnEye almost 4 years
    This is a great answer, it really is possible to run the WAR like this, the only drawback is that it seems to unpack it and keep that version, you cannot just change the WAR as you go, you need to re-import it every time it changes.