Ant buildfile does not contain a javac task - eclipse

I have build.xml file and I want to create Java project from Existing Ant Buildfile. But I have an error: Specified buildfile does not contain a javac task
My file has simple structure:
<project>
<target ...>
</target>
...
</project>

Provide javac to your build.xml as below:
<javac srcdir="src" destdir="bin" />

As Puneet Pandey pointed out, this error occurs when your build.xml file is lacking a <javac> XML element.
The <javac> XML element in the build.xml file (referred to as javac task) tells the compiler or IDE (Eclipse in this case) where the source Java files are for compiling. Once you know that it should be quite clear why Eclipse can't import your build.xml without a <javac> XML element.
In case you are not sure where to stick the <javac> tag I'll add a slightly fuller example. You will need to navigate to your build.xml and edit it so that it contains the <javac> line in the appropriate section inside the <project> tag.
<project ...>
<javac srcdir="src" destdir="bin" />
<target ...>
</target>
...
</project>

You need something like this,
<target name="compile">
<javac destdir="build/classes" srcdir="src" includeantruntime="false">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="build/${name}.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" casesensitive="no">
</fileset>
<lib dir="WebContent/WEB-INF/lib"/>
<classes dir="build/classes">
</classes>
</war>
</target>

Related

Flutter: Ant : You must not specify nested elements when using refid

On my flutter project by using junitreport I am making junit report but it is XML,
flutter test --machine | tojunit --output test.xml
Now by Ant, I want to make Html from it. test.xml is at the root of my project, here I made build.xml:
<project name="genTestReport" default="gen" basedir=".">
<description>
Generate the HTML report from JUnit XML files
</description>
<path id="classpath">
<pathelement location="/opt/homebrew/opt/ant/1.10.12/junit/junit-4.13.2.jar"/>
</path>
<target name="gen">
<property name="genReportDir" location="${basedir}/unitTestReports"/>
<delete dir="${genReportDir}"/>
<mkdir dir="${genReportDir}"/>
<junit printsummary="true" showoutput="true" fork="true">
<classpath refid="classpath">
<fileset dir="${basedir}">
<include name="test.xml"/>
</fileset>
</classpath>
<formatter type="xml"/>
</junit>
<junitreport todir="${basedir}/unitTestReports">
<fileset dir="${basedir}" includes="test.xml"/>
<report format="frames" todir="${genReportDir}/html"/>
</junitreport>
</target>
</project>
Now I run this command in root folder:
alt#Alis-MBP rr-front % ant -buildfile build.xml
Buildfile: /Users/alt/Projects/rr-front/build.xml
gen:
[delete] Deleting directory /Users/alt/Projects/rr-front/unitTestReports
[mkdir] Created dir: /Users/alt/Projects/rr-front/unitTestReports
BUILD FAILED
/Users/alt/Projects/RentReady/rr-portal-front/build.xml:13: You must not specify nested elements when using refid
Does it seem I need some configuration ?
The <junit> task is just for running the tests, which you already did outside Ant. So I think you only need the <junitreport> task in this case to convert the xml to html.
The reason for the error is that you put the fileset inside the classpath in the junit task:
<classpath refid="classpath">
<fileset dir="${basedir}">
<include name="test.xml"/>
</fileset>
</classpath>
When you use a refid, as you have in the classpath, you are saying "use this reference to define the classpath". Hence, if you use a refid and define the classpath with nested elements, there is a conflict.

Missing output files after running Ant script from Eclipse

I have a simple web application developed in the Eclipse Luna. The directory structure of the application is like:
Project name is SchoolSchedule.
Under the project name, there are Java Resources, build, WebContent folders, and the build.xml file.
Under Java Resources, it is the "src" folder and my Java code package name is under the "src" folder.
Under the WebContent, there are META-INF, WEB-INF and my jsp files
Under the WEB-INF, there are web.xml file and the "lib" directory.
The build.xml is at the project root. This web application runs successfully and produces expected results.
I created an Ant script to compile, build a WAR file, and deploy the WAR. But, even the basic task does not work. I right click on the build.xml --> run as ... --> Ant build. In the console, I can see all the echo messages and no error. However, I do not see any new directories created (I "refresh" the project.). No "class" files compiled from the Java code and not to mention build and deploy those tasks.
There is something I did not get it right. Please help. Here is my Ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntWarWebApp" basedir="." >
<echo>Define properties</echo>
<property name="name" value="SchoolSchedule"/>
<property name="src" location="src"/>
<property name="web" location="WebContent"/>
<property name="build" location="build"/>
<property name="classDir" location="${build}/src"/>
<property name="distDir" location="${build}/dist"/>
<property name="warDir" location="${build}/war"/>
<property name="tomcat.webapps" value="C:\apache-tomcat-7.0.70\webapps" />
<echo>time stamp</echo>
<tstamp prefix="build-info">
<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>
<echo>clean up previous build directories</echo>
<target name="clean" description="Delete old build directories">
<delete dir="${distDir}"/>
<delete dir="${warDir}"/>
<delete dir="${classDir}"/>
</target>
<echo>create directories</echo>
<target name="init" depends="clean">
<mkdir dir="${build}"/>
<mkdir dir="${classDir}"/>
<mkdir dir="${warDir}"/>
<mkdir dir="${distDir}"/>
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>
</target>
<echo>start compiling</echo>
<target name="compile" depends="clean, init" description="Compile main
source tree java files">
<javac srcdir="${src}" destdir="${classDir}" />
<classpath>
<fileset dir="${basedir}/WebContent/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</target>
<echo>start building WAR file</echo>
<target name="buildwar" depends="clean, init, compile">
<war basedir="${wardir}" destfile="${distDir}/${name}.war"
webxml="${wardir}/WEB-INF/web.xml">
<webinf dir="${wardir}/WEB-INF/">
<include name="**/*.jar" />
</webinf>
<manifest>
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
<echo>end building WAR file</echo>
<target name="deploy" depends="init, compile, buildwar" description="Deploy application">
<delete dir="${tomcat.webapps}/*.war" />
<echo>copy WAR file to Tomcat deploy directory</echo>
<copy file="${distdir}/*.war" todir="${tomcat.webapps}" />
</target>
</project>
Aren't you supposed to have some kind of top-level element
<project>
....
</project>
around all this?

How to build and deploy adapter with single ANT script Worklight 6.1

At 6.1 the ant jar was split into two jars: worklight-ant-builder.jar and worklight-ant-deployer.jar. I can run the build or the deploy tasks by themselves but I have to change the fileset. I want to run the build adapter and deploy adapter out of a single ant script.
I've tried a few ways to include both jars in the taskdef fileset:
include name="*.jar"
or
filename name="*.jar"
or
include name="worklight-ant-builder.jar"
include name="worklight-ant-deployer.jar"
Its almost like the tasks won't accept multiple jars. The build always works, but the deploy only when the deployer.jar is "include name="worklight-ant-deployer.jar" by itself.
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<fileset dir="${worklight.server.install.dir}/WorklightServer">
<include name="*.jar"/>
<!-- <filename name="*.jar"/> -->
<!-- <include name="worklight-ant-builder.jar"/> -->
<!-- <include name="worklight-ant-deployer.jar"/> -->
</fileset>
</classpath>
</taskdef>
I understand the multi-script answer but I think I shouldn't have to do that. This is my full script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="BuildDeployAdapter" basedir="." default="help">
<property name="worklight.server.install.dir" value="C:/IBM/Worklight61/"/>
<property name="adapter-source-files-folder" value="C:/Worklight/workspaces/base61p/HelloWorklight/adapters/HTTPAdapter"/>
<property name="destination-folder" value="C:/Worklight/workspaces/base61p/HelloWorklight/binANT"/>
<property name="myAdapter.adapter" value="${destination-folder}/HTTPAdapter.adapter"/>
<property name="http.server.port.context" value="http://mydomain:9080/worklight"/>
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<fileset dir="${worklight.server.install.dir}/WorklightServer">
<include name="*.jar"/>
<!-- <filename name="*.jar"/> -->
<!-- <include name="worklight-ant-builder.jar"/> -->
<!-- <include name="worklight-ant-deployer.jar"/> -->
</fileset>
</classpath>
</taskdef>
<target name="buildAdapter">
<adapter-builder
folder="${adapter-source-files-folder}"
destinationfolder="${destination-folder}"/>
</target>
<target name="deployAdapter">
<adapter-deployer deployable="${myAdapter.adapter}"
worklightserverhost="${http.server.port.context}"
userName="username" password="password" />
</target>
</project>
Right now I have to switch the included jar for each task, when I want to use the masked include - either include name=".jar" or filename name=".jar". This seems to be a limititation on the specific task not accepting more than one jar. Am I off base here?
Given the information you provided, it seems that a solution could be to create a separate script that would invoke the build and deploy scripts in sequence, like this:
<project name="Adapter Stuff" default="do.all" basedir=".">
<target name="do.all">
<ant antfile="path/to/worklight-build-adapter.xml"
target="build-target" inheritall="false"/>
<ant antfile="path/to/worklight-deploy-adapter.xml"
target="deploy-target" inheritall="false"/>
</target>
</project>

ant eclipse: package org.apache.log4j does not exist

I'm a java-greenhorn trying to compile my project via ant, but nothing's working.
So, in my class I'm using log4j.jar and import junit. Everything's in Eclipse, either Ant.
Here is the build.xml file:
<path id="master-classpath">
<pathelement path="D:\.a lot of folders..\junit.jar"/>
<!--<pathelement path="D:\...\log4j-1.2.17.jar"/> -->
<fileset dir="D:\apache-log4j-1.2.17">
<include name="log4j-1.2.17.jar"/>
</fileset>
<pathelement path="${buildSrc}"/>
</path>
And compile block:
<target name="compile" depends="init">
<javac includeantruntime="false" srcdir="${src1}" destdir="${buildSrc}"/>
<javac includeantruntime="false" srcdir="${src2}" destdir="${buildSrc}"/>
<javac includeantruntime="false" srcdir="${test}" destdir="${buildTest}">
<classpath refid="master-classpath"/>
</javac>
<javac includeantruntime="false" srcdir="src" destdir="build/classes" classpath="${buildSrc}"/>
</target>
I've also tried some different approaches, like making the same in the javac-task, using property, etc, to no success. Could you please, identify my mistake and help deal with it?
Thanks in advance.
<javac includeantruntime="false" srcdir="${test}" destdir="${buildTest}">
<classpath refid="master-classpath"/>
</javac>
should work. As should "classpathref" as an attribute on javac itself.
Possibilities:
Typo in folder name
Typo in file name
D drive isn't mapped

Could not find wsdlLocation in additional metadatafiles

I have jax-ws web service (jboss implementation) configured with annotation.
#WebService([...], wsdlLocation = "/WEB-INF/wsdl/service.wsdl")
The wsld file is included into war file. The war file is included into ear file, that is deployed on JBoss (version: 5.0.1.GA).
During deployment I receive error message like that:
"Could not find /WEB-INF/wsdl/service.wsdl in the additional metadatafiles!"
I tried to put the file in many places:
- META-INF folder of war file,
- META-INF folder of ear file,
- classpath of war file,
but I it didn't help.
Anyone knows how should I configure it?
i had the same problem and i solved like this:
#WebService(targetNamespace="http://my.app.it/", wsdlLocation = "WEB-INF/wsdl/additional.wsdl")
(WEB-INF not start with slash)
To address this issue, I placed the WSDLs into the jar file that I had created from the generated stubs. Then set the wsdllocation and all was good.
example of my ant target:
<target name="genclients" depends="clean, -createdirs">
<wsimport
fork="true"
xnocompile="true"
wsdl="${src.resource.dir}\${wsdl.name}"
wsdllocation="/resources/${wsdl.name}"
sourcedestdir="${src.generated.dir}"
verbose="true"
destdir="${target.classes.dir}"
keep="true"
extension="true"
debug="true"
package="com.fedex.ship.stub"
xadditionalHeaders="true"
binding="${basedir}/binding.xml"
>
<arg line="-mark-generated"/>
</wsimport>
<javac srcdir="${src.generated.dir}" destdir="${target.classes.dir}" includeantruntime="false" source="1.6" target="1.6" debug="true" deprecation="false" optimize="false" failonerror="true">
<include name="**/*.java"/>
</javac>
<copy todir="${target.classes.dir}" preservelastmodified="true" overwrite="true">
<fileset dir="${src.dir}" >
<include name="**/*.wsdl"/>
<include name="**/*.xsd"/>
</fileset>
</copy>
<pathconvert property="manifest.classpath" pathsep=" ">
<mapper>
<chainedmapper>
<flattenmapper />
</chainedmapper>
</mapper>
<path>
</path>
</pathconvert>
<mkdir dir="${target.classes.dir}/META-INF"/>
<manifest file="${target.classes.dir}/META-INF/manifest.mf">
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
<jar jarfile="${target.jar.dir}/${jar.name}" basedir="${target.classes.dir}" manifest="${target.classes.dir}/META-INF/manifest.mf" excludes=".settings,**/.svn"/>
<!--
<delete failonerror="false" includeEmptyDirs="true">
<fileset dir="${target.classes.dir}"/>
</delete>
-->
</target>