Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
59 views

How Do I Create A Jar File Using Ant - Web Tutorials - Pag 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

How Do I Create A Jar File Using Ant - Web Tutorials - Pag 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

http://www.avajava.com/tutorials/lessons/how-do-i-create-a-jar-file-using-ant.html?

page=3

Search Tutorials: Go

AVAJAVA Web Tutorials


Total Categories: 24, Total Tutorials: 508
Ant: 11 of 16 tutorials
How do I create a jar file using Ant?

Web Tutorials :: Ant :: 11. How do I create a jar file using Ant?

Tutorial Categories: How do I create a jar file using Ant?


1. Ajax (1) Author: Deron Eriksson
2. Ant (16) Description: This Ant tutorial describes how to use the jar task to build a jar file.

3. Apache Web Server (8) Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1

4. Bioinformatics (10)
5. Cascading Style Sheets (47) Page: < 1 2 3
6. Classes and Objects (14)
7. Database (13) (Continued from page 2)
8. Design Patterns (22)
9. Eclipse (39) This tutorial consisted of a total of three Ant S W files. The team-cakes-utilities build.xml file points to the build-main.properties and build-main.xml files within another project, ant-utilities, which is a general Ant build project that contains targets that multiple projects can use.
10. Files (62)
11. General Java (69) The team-cakes-utilities build.xml file is shown below:
12. JSPs (9)
13. Java Basics (11)
team-cakes-utilities build.xml
14. Linux (23)
15. Logging (5) <?xml version="1.0" encoding="UTF-8"?>
16. Maven (88) <project name="team-cakes-utilities" default="" basedir=".">

17. Search (12) <property name="project-name" value="${ant.project.name}" />


18. Servlets (20) <property file="../ant-utilities/build-main.properties" />
<import file="../ant-utilities/build-main.xml" />
19. Struts (1)
20. Text (19) </project>

21. Tomcat (8)


22. Version Control (8)
The ant-utilities and team-cakes-utilities projects can be seen here. Notice that in Eclipse's Ant view, the team-cakes-utilities project has available all the targets within the ant-utilities build-main.xml file. The build-jar target in the Ant view is highlighted.
23. Windows (2)
24. XML (1)

21/10/2014 10:42
http://www.avajava.com/tutorials/lessons/how-do-i-create-a-jar-file-using-ant.html?page=3

Here is the ant-utilities build-main.properties file:

ant-utilities build-main.properties

#build-main.properties file
project-name=ant-utilities
builder=TeamCakes
ftp-server=--
ftp-userid=--
ftp-password=--
tomcat-manager-url=http://--/manager
tomcat-manager-username=--
tomcat-manager-password=--
server-home-directory=--/--
email-to=--
email-from=--
tomcat-home=/apache-tomcat-5.5.20

Here is the ant-utilities build-main.xml file that contains the targets we mentioned above and many other useful targets.

ant-utilities build-main.xml

<?xml version="1.0" encoding="UTF-8"?>


<project name="ant-utilities" default="war" basedir=".">
<property file="build-main.properties" />

<property name="war-file-name" value="${project-name}.war" />


<property name="source-directory" value="src" />
<property name="classes-directory" value="bin" />
<property name="web-directory" value="web" />
<property name="web-xml-file" value="web/WEB-INF/web.xml" />
<tstamp prefix="build-info">

21/10/2014 10:42
http://www.avajava.com/tutorials/lessons/how-do-i-create-a-jar-file-using-ant.html?page=3
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
<format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />
</tstamp>
<property name="build-directory" value="build" />

<property name="ftp-remotedir" value="uploaded-wars" />

<path id="project-classpath">
<fileset dir="web/WEB-INF/lib" includes="*.jar" />
<fileset dir="${tomcat-home}/bin" includes="*.jar" />
<fileset dir="${tomcat-home}/common/lib" includes="*.jar" />
<fileset dir="${tomcat-home}/server/lib" includes="*.jar" />
</path>

<path id="jar-project-classpath">
<fileset dir="lib" includes="*.jar" />
<fileset dir="${tomcat-home}/bin" includes="*.jar" />
<fileset dir="${tomcat-home}/common/lib" includes="*.jar" />
<fileset dir="${tomcat-home}/server/lib" includes="*.jar" />
</path>

<taskdef name="start" classname="org.apache.catalina.ant.StartTask" />


<taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />

<target name="project-name-test">
<echo>hello, the project is: ${project-name}</echo>
</target>

<target name="stop" description="stop application in tomcat">


<stop url="${tomcat-manager-url}" username="${tomcat-manager-username}" password="${tomcat-manager-password}" path="/${project-name}" />
</target>

<target name="start" description="start application in tomcat">


<start url="${tomcat-manager-url}" username="${tomcat-manager-username}" password="${tomcat-manager-password}" path="/${project-name}" />
</target>

<target name="undeploy" description="undeploy from tomcat">


<undeploy failonerror="no" url="${tomcat-manager-url}" username="${tomcat-manager-username}" password="${tomcat-manager-password}" path="/${project-name}" />
</target>

<target name="deploy" description="deploy to tomcat">


<echo>deploying from client</echo>
<deploy url="${tomcat-manager-url}" username="${tomcat-manager-username}" password="${tomcat-manager-password}" path="/${project-name}" war="file:/projects/workspace/${project-name}/${build-directory}/${war-file-name}" />
</target>

<target name="deploy-from-server">
<echo>deploying server war file</echo>
<sleep seconds="5" />
<deploy url="${tomcat-manager-url}" username="${tomcat-manager-username}" password="${tomcat-manager-password}" path="/${project-name}" localwar="file:/${server-home-directory}/uploaded-wars/${war-file-name}" />
<echo>done deploying</echo>
</target>

<target name="war">
<mkdir dir="${build-directory}" />
<delete file="${build-directory}/${war-file-name}" />
<war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
<classes dir="${classes-directory}" />
<fileset dir="${web-directory}">
<!-- Need to exclude it since webxml is an attribute of the war tag above -->
<exclude name="WEB-INF/web.xml" />
</fileset>
<manifest>
<attribute name="Built-By" value="${builder}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>

<target name="ftp" depends="" description="upload war file to server">


<ftp server="${ftp-server}" remotedir="${ftp-remotedir}" userid="${ftp-userid}" password="${ftp-password}" action="mkdir" verbose="yes">
</ftp>
<ftp server="${ftp-server}" remotedir="${ftp-remotedir}" userid="${ftp-userid}" password="${ftp-password}" action="send" verbose="yes" depends="yes">
<fileset file="${build-directory}/${war-file-name}" />
</ftp>
</target>

<target name="pscp" depends="" description="securely upload war file to server">


<echo message="uploading war file to server using pscp" />
<exec executable="pscp.exe">
<arg value="-v" />
<arg value="-pw" />
<arg value="${ftp-password}" />
<arg value="${build-directory}/${war-file-name}" />
<arg value="${ftp-userid}@${ftp-server}:${ftp-remotedir}/${war-file-name}" />
</exec>
<echo message="done uploading war file to server using pscp" />

21/10/2014 10:42
http://www.avajava.com/tutorials/lessons/how-do-i-create-a-jar-file-using-ant.html?page=3
</target>

<target name="mail-build-and-deploy">
<mail from="${email-from}" tolist="${email-to}" subject="${war-file-name} was uploaded to the server and deployed" message="The ${war-file-name} file was uploaded to ${ftp-server}
in ${ftp-remotedir} and deployed to the /${project-name} context" />
</target>

<target name="clean">
<delete dir="bin" />
<mkdir dir="bin" />
</target>

<target name="copy-non-java-files">
<copy todir="bin" includeemptydirs="false">
<fileset dir="src" excludes="**/*.java" />
</copy>
</target>

<target name="compile" depends="clean,copy-non-java-files">


<javac srcdir="src" destdir="bin" classpathref="project-classpath" />
</target>

<target name="compile-jar-classes" depends="clean,copy-non-java-files">


<javac srcdir="src" destdir="bin" classpathref="jar-project-classpath" />
</target>

<target name="clean-jar">
<delete dir="build" />
<mkdir dir="build" />
</target>

<target name="jar">
<jar basedir="bin" destfile="build/${project-name}.jar">
<manifest>
<attribute name="Built-By" value="${builder}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</jar>
</target>

<target name="build-jar">
<antcall target="compile-jar-classes" />
<antcall target="clean-jar" />
<antcall target="jar" />
</target>

<target name="build-and-deploy-from-server" depends="war,ftp,undeploy,deploy-from-server,mail-build-and-deploy" />


<target name="build-and-deploy-from-server (secure)" depends="war,pscp,undeploy,deploy-from-server,mail-build-and-deploy" />
<target name="kitchen-sink" depends="compile,war,pscp,undeploy,deploy-from-server,mail-build-and-deploy" />
</project>

Page: < 1 2 3

Related Tutorials:

Ant :: How do I create a versioned jar file using Ant?


Ant :: How do I build a war file with Ant?
Ant :: How do I build a versioned war file?

Web Tutorials :: Ant :: 11. How do I create a jar file using Ant?

Copyright © 2014 Code Strategies | Template: Free CSS Templates | Contact

21/10/2014 10:42

You might also like