score:63
Accepted answer
Yes - click on File -> Export -> General -> Ant Buildfiles
and specify the file name, project, etc.
score:8
I find that I've got a single generic Ant build.xml that I reuse again and again. It's not something that has to be done from scratch every time.
If you're learning Ant, what's the point of using a generated build.xml?
Something like this:
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>
Source: stackoverflow.com
Related Query
- How to generate build.xml for a new java project?
- How to initialize git for a new eclipse (neon) java project
- How to generate a jar file for a java project and use the jar in an android project
- How to generate Ant and Maven build files for an Eclipse Java project?
- How to exclude referenced libraries from being exported when you export jar in VS Code for Java project (no build tool)
- How can I fix the project build path error? I can't import the java.lang.math for a Java 8/9 Calculator app
- How to Build a definition and publish test results for a Java project with maven, Junit and selenium on Visual Studios Team Services VSTS
- How can I generate warnings for non internationalized java strings at build time
- How to simultaneously run all JUnit tests for a Eclipse Java project without Maven?
- How Do I Automatically Generate A .jar File In An Eclipse Java Project
- How to create the pom.xml for a Java project with Eclipse
- How to use Gradle to generate Eclipse and Intellij project files for Android projects
- How do I build a Java project in Eclipse, to create an external JAR
- How to create a new layout for an Android project (using Eclipse)
- How can I build a jar for a previous Java version?
- How to get Eclipse to stop asking to create a module-info java file on new Java project creation?
- How to add @Override, @Deprecate and static modifiers to methods automatically for all project Java classes where necessary?
- How do you get Eclipse to auto-generate a main method for a new Java class?
- How to generate executable of java project in eclipse
- How to build Protobuf for Java in Windows via Eclipse
- How to use an existing Project as a template for a new one with Eclipse (CDT)?
- How do I use a Java project that requires a 1.7 compliance level on an Android project build path?
- How to have Eclipse Java EE automatically generate the exploded WAR for a web project?
- How to build Android project with Ant that depends on Java project?
- How to generate the Builder java class for your POJO
- How to setup a Java maven project for multiple developers to use easily
- How create a java project for both intellij and eclipse ide's
- No option for importing Java project from existing Ant build file in Eclipse Indigo
- Creating a new project in Eclipse using Maven as build tool for Google App Engine project
- How to setup a Java Eclipse (Juno) dynamic web project with Maven for App Engine
More Query from same tag
- Eclipse run test one by one
- Eclipse WindowBuilder is not accurate
- How to reload java class automatically in eclipse?
- How to ignore a specific warning in PyDev?
- How to auto terminate instances of Java application in eclipse?
- Application updates in emulator from Eclipse
- eclipse creating user library using variable to specify jars path
- Is there a way to quickly capitalize the variable name in Eclipse
- Install Marketplace plugin on Eclipse Juno
- Which version of Eclipse should I be downloading?
- Maven dependency update on commandline
- RESTful servise
- where to add eclipse extension
- How can I add a library to portable Eclipse?
- What is your favorite eclipse plugins for c / c++ development?
- Is there a way to have multiple lines of text in one array element for Java?
- Creating a list of assignments for a school project, but I'm getting a NullPointerException
- in eclipse: NullPointerException at org.eclipse.e4.ui.workbench.addons.dndaddon.DragAgent.dragFinished(DragAgent.java:171)
- what does the following lines of code mean in eclipse plugin.xml?
- Classpath trouble using JUnit with both Eclipse and Maven
- How to get a fortran90 code migrated to eclipse(photran) on windows?
- Eclipse mac osx: Launch failed, binary not found
- Move Eclipse to another machine?
- Zoom Editor Font Size through Keyboard Shortcuts in Eclipse
- Refresh PyDev import paths in Eclipse
- Activity has leaked window.com.android.internal.policy.impl.PhoneWindow$DecorView
- How do I remove the default layout and show a splash screen instead with Phonegap 2.9?
- Getting error in WindowBuilder in Eclipse because digits are being shown in different language
- How to get only some files to the Eclipse 'Package Explorer' tree (for Scala)
- Java: how to detect the current java runtime is a JRE or JDK?