Java ANT
To use ANT, create a file with the name "Build.xml" inside any Java Project. When you run, you have to run as ANT Build.
Print Message: "Welcome !"
To use ANT, create a file with the name "Build.xml" inside any Java Project. When you run, you have to run as ANT Build.
Print Message: "Welcome !"
<project name="PrintMessage" default = "class1" basedir = ".">
<target name = "class1">
<echo> Welcome ! </echo>
</target>
</project>
OR
<project name="PrintMessage" default = "class1" basedir = ".">
<target name = "class1">
<echo message = "Welcome !" />
</target>
</project>
Output:
class1:
[echo]
Welcome !
BUILD SUCCESSFUL
-------------------------------------------------------------------------------------
<project name="CreateNdeleteFolders" default = "createFolder" basedir = ".">
<!--
This is comment : Below target deletes the existing folders (if already
existing otherwise first create the folders and then delete.) -->
<target name = "deleteFolder" depends = "createFolder">
<delete dir = "Folder1" />
<delete dir = "Folder2" />
<delete dir = "Folder3" />
</target>
<!--
Below target creates new folders -->
<target name = "createFolder">
<mkdir dir = "Folder1" />
<mkdir dir = "Folder2" />
<mkdir dir = "Folder3" />
</target>
</project>
OutPut:
Buildfile: C:\Path\Build.xml
createFolder:
[mkdir] Created
dir: C:\Path\Folder1
[mkdir] Created
dir: C:\Path\Folder2
[mkdir] Created
dir: C:\Path\Folder3
deleteFolder:
[delete] Deleting
directory C:\Path\Folder1
[delete] Deleting
directory C:\Path\Folder2
[delete] Deleting
directory C:\Path\Folder3
BUILD SUCCESSFUL
Total time: 499 milliseconds
--------------------------------------------------------------------------------------------
COPY FILES AND FOLDERS
<project name="copyFolderNFiles" default = "copyFiles" basedir = ".">
<!-- Below target copies folders and files -->
<target name = "copyFolder">
<!--
copy folders from src location excluding the folder "Skipfolder"
-->
<copydir dest = "C:\destFolder" src="C:\scrFolder" excludes = "**/SkipFolder**"></copydir>
</target>
<target name = "copyFiles" depends = "copyFolder">
<!--
copy selected files overwritting if already exists -->
<copy todir ="C:\destFolder" overwrite = "true" >
<fileset dir = "C:\scrFolder" includes = "**/*.java"></fileset> <!-- This copies multiple files with extension "java"
-->
</copy>
</target>
</project>
---------------------------------------------------------------------------------------------
Compile and run a java
class:
<project name="CompileNrun" default = "run" basedir = "."
<target name = "ToCompile">
<delete dir="build"/> <!-- delete the folder if already existing
-->
<mkdir dir="build/classes"/>
<javac includeantruntime = "false" srcdir = "C:\srcFolder" destdir = "C:\destFolder" includes = "**/*.java"></javac>
<!-- copile ".java" files in every folder inside src folder
-->
</target>
<target name = "Run" depends = "ToCompile">
<java classname = "packageName.className">
<classpath path="C:\destFolder" />
</java>
</target>
</project>Answer:
ToCompile:
[delete] Deleting directory C:\srcFolder\build
[mkdir] Created dir: C:\destFolder\build\classes
[javac] Compiling 2 source files to C:\destFolder\build\classesRun:
[java] Hello World. <!-- The class was executed with this print statement -->
BUILD SUCCESSFUL
No comments:
Post a Comment