How to create military files

What are the best methods for creating military files (using eclipse) to run on tomcat? study guides, links, examples are highly appreciated.

+85
java eclipse tomcat war
Jun 16 '09 at 14:06
source share
13 answers

You can use Ant to configure, compile, WAR , and deploy your solution.

<target name="default" depends="setup,compile,buildwar,deploy"></target> 

You can then do one click in Eclipse to launch this Ant target. The following are examples of each step:

Background

Suppose your code is organized like this:

  • ${basedir}/src : Java files, properties, XML configuration files
  • ${basedir}/web : your JSP files
  • ${basedir}/web/lib : any JAR files needed at runtime
  • ${basedir}/web/META-INF : your manifest
  • ${basedir}/web/WEB-INF : your web.xml files

Customization

Define a setup task that creates a distribution directory and copies any artifacts that should be WARNING directly:

 <target name="setup"> <mkdir dir="dist" /> <echo>Copying web into dist</echo> <copydir dest="dist/web" src="web" /> <copydir dest="dist/web/WEB-INF/lib" src="${basedir}/../web/WEB-INF/lib" /> </target> 

Compile

Create your Java files in classes and copy any artifacts other than Java that are in src but should be available at runtime (e.g. properties, XML files, etc.):

 <target name="compile"> <delete dir="${dist.dir}/web/WEB-INF/classes" /> <mkdir dir="${dist.dir}/web/WEB-INF/classes" /> <javac destdir="${dist.dir}/web/WEB-INF/classes" srcdir="src"> <classpath> <fileset dir="${basedir}/../web/WEB-INF/lib"> <include name="*" /> </fileset> </classpath> </javac> <copy todir="${dist.dir}/web/WEB-INF/classes"> <fileset dir="src"> <include name="**/*.properties" /> <include name="**/*.xml" /> </fileset> </copy> </target> 

Build WAR

Create your own WAR:

 <target name="buildwar"> <war basedir="${basedir}/dist/web" destfile="My.war" webxml="${basedir}/dist/web/WEB-INF/web.xml"> <exclude name="WEB-INF/**" /> <webinf dir="${basedir}/dist/web/WEB-INF/"> <include name="**/*.jar" /> </webinf> </war> </target> 

Deploy

Finally, you can configure the task to deploy the WAR directly at the Tomcat deployment location:

 <target name="deploy"> <copy file="My.war" todir="${tomcat.deploydir}" /> </target> 

Click and go!

Once all this is set up, just starting the default target from Eclipse will compile, WAR and deploy your solution.

The advantage of this approach is that it will work outside of Eclipse, as well as in Eclipse and can be used to easily share a deployment strategy (for example, using source control) with other developers who are also working on your project.

+91
Jun 16 '09 at 14:22
source share

I always chose Export from Eclipse. It creates a war file and includes all the necessary files. Giving you a project as a web project is all that you need to do. Eclipse makes this very easy.

+34
Jun 16 '09 at 14:12
source share

We use Maven (Ant Big Brother) for all our java projects, and it has a very excellent WAR plugin. Here you can find tutorials and usage.

It is much simpler than Ant, fully compatible with Eclipse (use maven eclipse: eclipse to create Eclipse projects) and is easy to configure.

Maven Homepage

Maven WAR plugin

Configuration Example:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1-alpha-2</version> <configuration> <outputDirectory>${project.build.directory}/tmp/</outputDirectory> <workDirectory>${project.build.directory}/tmp/war/work</workDirectory> <webappDirectory>${project.build.webappDirectory}</webappDirectory> <cacheFile>${project.build.directory}/tmp/war/work/webapp-cache.xml</cacheFile> <nonFilteredFileExtensions> <nonFilteredFileExtension>pdf</nonFilteredFileExtension> <nonFilteredFileExtension>png</nonFilteredFileExtension> <nonFilteredFileExtension>gif</nonFilteredFileExtension> <nonFilteredFileExtension>jsp</nonFilteredFileExtension> </nonFilteredFileExtensions> <webResources> <resource> <directory>src/main/webapp/</directory> <targetPath>WEB-INF</targetPath> <filtering>true</filtering> <includes> <include>**/*.xml</include> </includes> </resource> </webResources> <warName>Application</warName> </configuration> </plugin> 
+22
Jun 16 '09 at 14:19
source share

A war file is just a jar file with a military extension, but what makes it work is how the content is actually structured.

The J2EE / Java EE tutorial can be run:

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/WebComponents3.html

And the Servlet specification contains gory details:

http://java.sun.com/products/servlet/download.html

If you are creating a new web project in Eclipse (I mean the Java EE version), the structure is created for you, and you can also specify where your Application Server is installed and it will deploy and run the application for you.

Using the "Export-> WAR file" option will allow you to save the war file.

+14
Jun 16 '09 at 14:23
source share

If you don’t know what to do and start from scratch, Maven can help you get started.

By following the steps below, you can get a new military project setup in Eclipse.

  • Download and install Maven
  • Go to the command line: mvn archetype:generate
  • Follow the prompts: choose a simple java web project (18) and a suitable name.
  • When it's finished, run: mvn eclipse:eclipse
  • Launch Eclipse. Choose File β†’ Import β†’ Existing Project. Select the directory where you started the mvn targets.
  • So you now have a very good start to a military project in eclipse
  • You can create a war yourself by running mvn package or deploying it, setting up a server in eclipse and simply adding a project to the server.

As some others claim, the downside of using maven is that you have to use maven conventions. But I think that if you are just starting out, studying conventions is a good idea before you start creating your own. There is nothing stopping you from changing / refactoring to your preferred method at a later point.

Hope this helps.

+12
Jun 16 '09 at 22:12
source share
+4
Jun 16 '09 at 14:17
source share

Use ant build code I use this for my SMS project

 <property name="WEB-INF" value="${basedir}/WebRoot/WEB-INF" /> <property name="OUT" value="${basedir}/out" /> <property name="WAR_FILE_NAME" value="mywebapplication.war" /> <property name="TEMP" value="${basedir}/temp" /> <target name="help"> <echo> -------------------------------------------------- compile - Compile archive - Generate WAR file -------------------------------------------------- </echo> </target> <target name="init"> <delete dir="${WEB-INF}/classes" /> <mkdir dir="${WEB-INF}/classes" /> </target> <target name="compile" depends="init"> <javac srcdir="${basedir}/src" destdir="${WEB-INF}/classes" classpathref="libs"> </javac> </target> <target name="archive" depends="compile"> <delete dir="${OUT}" /> <mkdir dir="${OUT}" /> <delete dir="${TEMP}" /> <mkdir dir="${TEMP}" /> <copy todir="${TEMP}" > <fileset dir="${basedir}/WebRoot"> </fileset> </copy> <move file="${TEMP}/log4j.properties" todir="${TEMP}/WEB-INF/classes" /> <war destfile="${OUT}/${WAR_FILE_NAME}" basedir="${TEMP}" compress="true" webxml="${TEMP}/WEB-INF/web.xml" /> <delete dir="${TEMP}" /> </target> <path id="libs"> <fileset includes="*.jar" dir="${WEB-INF}/lib" /> </path> 

+3
Nov 12 '09 at 5:56
source share

Another option is to create it automatically using Eclipse. Of course, if you have a continuous Ant integration environment or Maven is recommended. The export alternative is not very convenient, because you must configure the export properties each time.

STEPS:

  • Enable support for Project Archives; it may depend on your project (I used it in a Java EE / Web project). Right-click the project root directory; Configure β†’ Add support for project archives.

  • Go in and create a new archive in the Project Archives main directory. You only have the jar option, but the name you are archiving * .war.

  • Configure a set of files, i.e. which files will be included. It is typical to configure two sets of files in the same way that a web deployment assembly (project property) is configured.

    • copy / WebContent in /
    • copy / build / classes for WEB-INF / classes (create this set of files after defining the WEB-INF / classes directory in the archive)
  • You may need the tweek exclude property for files, depending on where you placed some configuration files, or you may need more sets of files, but the idea is that after you configure this, you do not need to change it.

  • Create an archive manually or publish directly to the server; but also automatically created for you by Eclipse

+2
May 29 '13 at 12:22
source share

Another common option is gradle.

http://www.gradle.org/docs/current/userguide/application_plugin.html

To create your war file in a web application:

In build.gradle add:

 apply plugin: 'war' 

Then:

 ./gradlew war 

Use the layout from the accepted answer above.

+2
Jan 23 '15 at 13:30
source share

A simplified solution that also updates the Eclipse workspace:

 <?xml version="1.0" encoding="UTF-8"?> <project name="project" default="default"> <target name="default"> <war destfile="target/MyApplication.war" webxml="web/WEB-INF/web.xml"> <fileset dir="src/main/java" /> <fileset dir="web/WEB-INF/views" /> <lib dir="web/WEB-INF/lib"/> <classes dir="target/classes" /> </war> <eclipse.refreshLocal resource="MyApplication/target" depth="infinite"/> </target> </project> 
0
Mar 28 '15 at 17:40
source share

Simplified shell code for creating WAR files from the Eclipse standard dynamic web project. Uses the RAM file system (/ dev / shm) on the Linux platform.

 #!/bin/sh UTILITY=$(basename $0) if [ -z "$1" ] ; then echo "usage: $UTILITY [-s] <web-app-directory>..." echo " -s ..... With source" exit 1 fi if [ "$1" == "-s" ] ; then WITH_SOURCE=1 shift fi while [ ! -z "$1" ] ; do WEB_APP_DIR=$1 shift if [ ! -d $WEB_APP_DIR ] ; then echo "\"$WEB_APP_DIR\" is not a directory" continue fi if [ ! -d $WEB_APP_DIR/WebContent ] ; then echo "\"$WEB_APP_DIR\" is not a Web Application directory" continue fi TMP_DIR=/dev/shm/${WEB_APP_DIR}.$$.tmp WAR_FILE=/dev/shm/${WEB_APP_DIR}.war mkdir $TMP_DIR pushd $WEB_APP_DIR > /dev/null cp -r WebContent/* $TMP_DIR cp -r build/* $TMP_DIR/WEB-INF [ ! -z "$WITH_SOURCE" ] && cp -r src/* $TMP_DIR/WEB-INF/classes cd $TMP_DIR > /dev/null [ -e $WAR_FILE ] && rm -f $WAR_FILE jar cf $WAR_FILE . ls -lsF $WAR_FILE popd > /dev/null rm -rf $TMP_DIR done 
0
Dec 19 '16 at 20:29
source share

Use this command outside the WEB-INF folder. This should create your war file. This is the fastest method I know.

You will need JDK 1.7+ to achieve these variables and environment variables that point to the bin directory of your JDK.

 jar -cvf projectname.war * 

Link Link

0
Feb 13 '17 at 8:56 on
source share

** Create a war file in Eclips Gaynemed from the grails web project **

1. Import of the project:

2. Modify the datasource.groovy file

Like this: url = "jdbc: postgresql: //18.247.120.101: 8432 / PGMS"

2.chnge AppConfig.xml

3.kill Java from task manager:

  1. run a clean command in eclipses

  2. Run 'prod war', which will indicate the name of the project.

  3. Check the log file and find the same .war file in the Workbench directory with the same date.

-2
Jan 30 '15 at 6:56
source share



All Articles