I need Eclipse to deploy the WAR file my ANT script builds, not what it builds internally

10,641

Eclipse deploys a web application by looking at the Web Deployment Assembly options for your project. You can see this by right-clicking the project, choosing Properties, and then click on Deployment Assembly. Eclipse usually uses an expanded directory deployment here rather than creating and deploying a WAR (this is based on the server plugin being used, but I think most of them use an expanded directory structure for speed). If you export as a WAR it will create a WAR with the same content.

There are two main choices to do what you'd like:

  • Modify the Web Deployment Assembly options to match exactly what you would like in the deployed app

  • Don't use Eclipse's deployment; add an "External Ant Builder" to the "Builders" options for your project (right-click project, choose Properties->Builders). You can then select which targets in the ant file you want to use when eclipse builds the project. One of these options can be a deployment step

Share:
10,641
Gordon
Author by

Gordon

Updated on June 04, 2022

Comments

  • Gordon
    Gordon about 2 years

    I'm using Eclipse Helios. I have a dynamic web project going and I've set up Eclipse to use an Ant Builder to generate a WAR file. This all works fine; if I change a .java file, Eclipse automatically runs my build.xml via Ant and updates my WAR. If I deploy the WAR to an external instance of Tomcat, it works perfectly.

    However, when I tell Eclipse to run my project under Tomcat, it is not using the WAR file generated by the Ant build, or using my Ant script to generate a temporary WAR.

    I know this because my build.xml script includes some additional XML configuration files in WEB-INF/classes in the WAR that are not ending up in the WEB-INF/classes dir that Eclipse pushes out.

    I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".

    An alternate approach would be to tell Tomcat when it is building a WAR to do so by adding a list of files, but I can't seem to find a way to do that either.

    I'm also curious how Eclipse knows what to publish since it is obviously ignoring my build.xml and my previously-generated WAR file.

  • Gordon
    Gordon over 13 years
    I guess I'll have to go with option 2 then, mainly because option 1 doesn't allow me to add specific files, only folders and archives. Thanks!
  • Scott Stanchfield
    Scott Stanchfield over 13 years
    I believe you can set it up to deploy the contents of a folder to the root folder of the WAR, if that's what you need.
  • Gordon
    Gordon over 13 years
    That won't work here as I need to copy specific files to the WEB-INF/classes dir so they are on the classpath when the app loads.
  • Gordon
    Gordon over 13 years
    To follow up, I did end up refactoring my project a bit to create a directory for these configuration files that I then export via the Deployment Assembly option as Scott described.