Question

It's 5 button clicks to get eclipse to create a deployable war file for my eclipse project, I figure there's probably some eclipse command line option to do the same thing, so I can just write it into a script, but I'm not seeing it.

Was it helpful?

Solution

Use the Ant war task, set up a relevant build file and you can just hit the "external tools" button to execute it.

OTHER TIPS

You could also setup a Maven build for your web project. Typing mvn package from the command line would then build the project for you.

For integration between Maven and Eclipse, see m2Eclipse and Maven Eclipse Plugin.

I cannot say anything about the WAR packaging itself, sorry.

But as I wrote in How do I automatically export a WAR after Java build in Eclipse? : If you can describe the WAR packaging with an Ant script, you can have that Ant script being executed automatically after each change to your project. Use Project->Properties->Builders->Add->Ant Builder. Give that builder you custom Ant script and it will automatically be executed after the "normal" builders of your project. You can even specify in the settings of the builder, if it shall only react on changes to specific files and so on.

The Ant builder is kind of a Swiss army knife for anything you want to automate in the project build without having to use the big tools like maven.

This Ant script should work for standard Dynamic Web Project structure of project:

Create Ant build.xml with replacing of two properties at begining:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Deploy From Eclipse to JBoss" basedir="." default="deploy">

  <!-- This replace with yours project name and JBoss location: -->
  <property name="warfile" value="MyProject"/>
  <property name="deploy" value="/home/honza/jboss-as-7.1.1.Final/standalone/deployments"/>

  <target name="create">
    <war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
      <classes dir="build\classes"/>
      <fileset dir="WebContent">
        <exclude name="WEB-INF/web.xml"/>
      </fileset>
    </war>
  </target>
  <target name="copy">
    <copy todir="${deploy}" overwrite="true">
      <fileset dir=".">
        <include name="${warfile}.war"/>
      </fileset>
    </copy>
  </target>
  <target name="clear">
    <delete includeemptydirs="true">
      <fileset dir="${deploy}" defaultexcludes="false">
        <include name="${warfile}.*/**" />
      </fileset>
    </delete>
  </target>
  <target name="deploy">
    <antcall target="create"/>
    <antcall target="clear"/>
    <antcall target="copy"/>
  </target>
</project>

Now should command "ant" do WAR creation and copy them to the JBoss. JBoss automatically deploys wars which finds in deployment directory.

For automatic run after build (Project - Build) add this Buildfile here:

MyProject - Properties - New - Ant builder
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top