I have created one files sharing application using socket programming where there is a indexing server and few clients are connected to server. I have to created one automation script using ant but i can only open one terminal with help of jar. how to open multiple terminals with help of one jar so that all clients and server terminals get open in just one click.
****Please find build ant file below:-****
<?xml version="1.0"?>
<project name="fax" basedir="." default="build">
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="fax"/>
<property name="projectName" value="Test" />
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="build" description="Compile source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.5" target="1.5" includeantruntime="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<jar destfile = "${web.dir}/lib/util.jar"
basedir = "${build.dir}/">
<manifest>
<attribute name = "Main-Class" value = "Client1"/>
</manifest>
</jar>
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
</project>
Related
I'm receiving an error message from Ant when I try to run the Javadoc ant task.
"BUILD FAILED
/data/data/com.termux/files/home/LearnJava/Observer/build.xml:39: No source files, no packages and no modules have been specified."
The build files reside at:
https://github.com/Fernal73/LearnJava/blob/master/Observer/build.properties
version=1.0.0
main.class=com.javacodegeeks.patterns.observerpattern.TestObserver
main.class1=com.javacodegeeks.patterns.observerpattern.Test
cs.properties=../checkstyle.properties
gformat.properties=../gformat.properties
ant.build.javac.source=1.7
ant.build.javac.target=1.7
packages=com.javacodegeeks.patterns.observerpatern.*
and
https://github.com/Fernal73/LearnJava/blob/master/Observer/build.xml
<?xml version="1.0"?>
<project name="Observer" default="main"
basedir=".">
<property file = "build.properties"/>
<property file = "${cs.properties}"/>
<property file = "${gformat.properties}"/>
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="." />
<property name="build.dir" location="." />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<taskdef resource="${cs.taskdef.resource}"
classpath="../${cs.jar}"/>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete>
<fileset dir="." includes="**/*.class"/>
</delete>
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir,gformat,checkstyle">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}">
<compilerarg value="-Xlint:-options"/>
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="${packages}" additionalparam="-Xdoclint:none"
sourcepath="${src.dir}"
destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="*.java" />
</fileset>
</javadoc>
</target>
<target name="manifest">
<tstamp/>
<manifest file="manifest.mf">
<attribute name="Built-By" value="${user.name}"/>
<section name="common">
<attribute name="Specification-Title" value="${ant.project.name}"/>
<attribute name="Specification-Version" value="${version}"/>
<attribute name="Specification-Vendor" value=""/>
<attribute name="Implementation-Title" value=""/>
<attribute name="Implementation-Version" value="${build} ${TODAY}"/>
<attribute name="Implementation-Vendor" value=""/>
</section>
<attribute name="Main-Class" value="${main.class}" />
</manifest>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile,manifest">
<jar destfile="${dist.dir}\${ant.project.name}.jar" basedir="${build.dir}" includes="**/*.class"
manifest="manifest.mf">
</jar>
</target>
<target name="run" >
<description>Run target</description>
<java classname="${main.class}">
<classpath>
<pathelement location="${dist.dir}\${ant.project.name}.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<target name="gformat">
<exec executable="find" dir="${basedir}"
failonerror="true" outputproperty="sources">
<arg line=" . -type f -name '*.java'"/>
</exec>
<echo message="About to format ...: ${sources}"/>
<java classname="${gformat.main.class}">
<arg line=" -i ${sources}"/>
<classpath>
<pathelement location="../${gformat.jar}"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<target name="checkstyle">
<first id="checkstylefile">
<fileset dir=".." includes="${cs.config}"/>
</first>
<checkstyle config="${toString:checkstylefile}"
classpath="../${cs.jar}"
failOnViolation="false" properties="${cs.properties}">
<fileset dir="${src.dir}" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="plain" toFile="${cs.output}"/>
</checkstyle>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
</target>
</project>
respectively.
My other projects on the repository have similar configurations.
They work as expected.
Am I missing something obvious?
I did miss something obvious. An extra 't' in the property packages. Evidently, I'm going to need two sets of eyes for this or a fresh set, a few hours later!
NOW, how do I close this?
I think the problem is in following part:
<fileset dir="${src.dir}">
<include name="*.java" />
</fileset>
In Ant "*.java" means all files with names matching *.java. This does not search in subdirectories.
To include all subdirectories you must specify:
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
But since you already specified the sourcePath attribute I'm wondering if you can't just remove the fileset element as ant will add **/*.java by default.
I am new to Ant and just followed a tutorial on how to do this. My goal is to create a .jar with manifest. But during build, the .jar is not created inside the "lib" folder. There are no errors during build so I'm kinda lost.
here's what inside the build.xml:
<?xml version="1.0"?>
<project name="converter" default="main" basedir=".">
<property name="projectName" value="Converter" />
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="lib.dir" location="lib"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="converter"/>
<property name="main-class" value="com.ouc.mv90.conversion.CSVtoMV90Converter" />
<!-- external libraries classpath, we don't need sources and javadoc -->
<path id="classpath">
<fileset dir="${basedir}/">
<include name="${lib.dir}/*.jar" />
<exclude name="${lib.dir}/*sources.jar"/>
<exclude name="${lib.dir}/*javadoc.jar"/>
</fileset>
</path>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="${lib.dir}/*.jar" />
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="build" description="Compile source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.5" target="1.5">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="init">
<mkdir dir="${build.dir}" />
</target>
<target name="compile" depends="init" description="compile the source ">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath" />
</target>
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="jar" depends="compile" description="package, output to JAR">
<jar jarfile="${lib.dir}/${projectName}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="${classpath.name}" />
</manifest>
</jar>
</target>
<!-- Default, run this -->
<target name="main" depends="clean, compile, jar" />
</project>
Hi I'm working on a project where i'm told to create dist ant target which creates JAR file and jrun target which depends on dist target ant should run dist created jar file. While ant jrun i get the folowing error : jrun
[java]: no main manifest attribute in *\build\jar\navus.jar
<?xml version="1.0" encoding="UTF-8"?>
<project name="POS" default="build" basedir=".">
<!-- Project properties-->
<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main.class" value="ee.ut.math.tvt.navus.Intro"/>
<!-- Different classpaths form compiling and running-->
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="run.classpath">
<pathelement location="${classes.dir}"/>
<path refid="compile.classpath"/>
</path>
<!-- Clean existing build-->
<target name="clean">
<delete dir="${build.dir}" />
</target>
<!-- Builds Java code-->
<target name="build" depends="clean">
<mkdir dir="${build.dir}"/>
<mkdir dir="${classes.dir}"/>
<copy file="${src.dir}/log4j.properties" todir="${classes.dir}" overwrite="true" />
<javac
srcdir="${src.dir}"
destdir="${classes.dir}">
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- Creates jar file-->
<target name="dist" depends="build">
<mkdir dir="${jar.dir}"/>
<propertyfile file="version.properties">
<entry key="build.revision.number" type="int" default="0" operation="+"/>
</propertyfile>
<jar jarfile="${build.dir}/jar/navus.jar"
basedir="${build.dir}/classes">
<manifest>
<attribute name="mainClass" value="${main.class}"/>
</manifest>
<fileset dir="${basedir}" includes="${src.dir}"/>
</jar>
</target>
<!-- Executes application via class Intro-->
<target name="run" depends="build"
description="runs introUI via Intro" >
<java classname="${main.class}"
classpathref="run.classpath"
fork="yes">
</java>
</target>
<!-- Runs application using JAR file-->
<target name="jrun" depends="dist"
description=" Run JAR file">
<java jar="${jar.dir}/navus.jar"
fork="yes"/>
</target>
</project>
Looking at google returns https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html. Maybe try something like this -
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="oata.HelloWorld"/>
</manifest>
</jar>
</target>
You need to create a manifest file (MANIFEST.MF), which goes inside the META-INF folder inside your jar. It resembles this:
Manifest-Version: 1.0
Application-Name: MyApp
Sealed: true
Main-Class: com.mysite.myappname.myMainClass
Codebase: www.mysite.com
My Eclipse project has the following structure:
-- | My project
|-src
|-build
|-doc
|-lib
In lib are placed my jar files. These files have been added to the Build path with "Add to Buildpath command". The project successfully compiles.
I want to build the project with Ant, to this aim I wrote the following xml file
<project name="ABTestConnector" basedir=".">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="test.Prova"/>
<property name="lib.dir" value="/lib"/>
<property name="doc.dir" value="/doc"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<path id="class-path">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}">
<classpath refid="class-path"/>
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<fileset dir="${classes.dir}" includes="**/*.class" />
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
<target name="doc" depends="clean-build" description="generate javadoc">
<javadoc sourcepath="${src.dir}" destdir="${doc.dir}"/>
</target>
I have also tried in the fileset: include name="**/*.jar"/>
But I still get the errors
[javac] /home/bruno/Documenti/TestingEnvironment/EclipseWorkspace/SeleniumABTestConnector_0.0.1/src/driversTod/TodSelenium.java:10: package org.openqa.selenium does not exist
[javac] import org.openqa.selenium.By;
Thank you in advance.
I am new to ANT and to use it, I simply created a new java project in Eclipse that just print the word Welcome in the screen. I ran the program using Eclipse and "Welcome" was successfully printed on the screen. This is my program
public class welcome {
public static void main(String[] args)
{
System.out.println("Welcome!!!");
}
}
Then I just followed the usual way to build ANT file using Eclipse so I used Export feature and choose ANT buildfile.
This the buildfile I have got:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. --><project basedir="." default="build" name="test">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../usr/lib/eclipse"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="test.classpath">
<pathelement location="bin"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="test.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="welcome">
<java classname="welcome" failonerror="true" fork="yes">
<classpath refid="test.classpath"/>
</java>
</target>
</project>
when I ran the program as Ant, it only gives me a message that build successful! without printing the "Welcome" word on screen!
This is the output
> Buildfile: /home/name/workspace/test/build.xml
> build-subprojects: init: build-project:
> [echo] test: /home/name/workspace/test/build.xml build: BUILD SUCCESSFUL Total time: 376 milliseconds
The default target of your ant file is "build" which will create a jar file of your project (which can be then executed later). If you want to run your project via ant, change the target to "welcome" (see the end of your ant file). That should execute the program as you expected.
Apache Ant is a Java library and command-line tool whose mission is to
drive processes described in build files as targets and extension
points dependent upon each other. The main known usage of Ant is the
build of Java applications
Also class names first letter should be CAPITALIZED ...
More or less this is how your ant should look like, but i still dont understand why you want to use ANT for whatever you are trying to do here.
<project name="Welcome" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="(packagename).(class name)"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>