Ant mapper returns escaped paths - java

This is not truly a YUI-related question.
I am trying to use YUI Compressor(in fact a .jar application) for multiple JS files. I would like to get those files automatically(as opposed to specifying every file's name in build.xml).
Here is my build.xml file:
<?xml version="1.0" encoding="utf-8"?>
<project name="CUIProject" default="prod">
<target name="-load.properties">
<loadproperties>
<file file="minify.properties"/>
</loadproperties>
</target>
<!--Minify JS files-->
<target name="-js.minify">
<apply executable="java" parallel="false" dest="${build.dir}">
<fileset dir="${src.dir}"/>
<mapper>
<globmapper from="*.js" to="*-min.js" handledirsep="yes"/>
</mapper>
<arg value="-jar"/>
<arg path="${minifier.dir}"/>
<srcfile/>
<arg value="-o"/>
<targetfile/>
</apply>
</target>
<!--Build-->
<target name="prod"
depends="
-load.properties,
-js.minify
">
</target>
</project>
The problem is that I get a FileNotFound exception because for some reason the <targetdir/> is somehow escaped: the \ separator from Windows is used as an escaping character, so my path because just one very large word.
How can I avoid such a behavior?

I had the same issue with YUI. The easiest way I found is to use the Ant-Contrib <for> task.
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${antlib.dir}/antcontrib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<!-- Minimize Concatinated JavaScript Files -->
<for param="concat.dir">
<dirset dir="${work.js.dir}">
<include name="*"/>
</dirset>
<sequential>
<echo message="[java] Minimized #{concat.dir}/concat-${build.id}-min.js>"/>
<java jar="${yui.compressor.jar}"
failonerror="true"
fork="true">
<arg value="-o"/>
<arg value="#{concat.dir}/concat-${build.id}-min.js"/>
<arg value="#{concat.dir}/concat-${build.id}.js"/>
</java>
</sequential>
</for>
Also take a look at the <pathconvert> task. This will convert the path separator from one OS to another. This may fix your issue. The File Mapper page in Ant's manual contains some examples using <pathconvert>.

Related

Compile vaadin widgetset from command line

In eclipse there is a plugin for vaadin.
When mark *.widgetset file in your project and click on on Compile vaading widgetset it compiles widgetset under WebContent\VAADIN\widgetsets. So my question is how to do it from command line without eclipse?
Note that: I've searched, but there are example of maven. This is old project and there is not maven configuration in it
You did not say which Vaadin version you are using but compiler class at least in Vaadin7 seems to be this:
https://vaadin.com/api/framework/7.6.8/com/vaadin/tools/WidgetsetCompiler.html
Not sure of commandline but I have this kind of ANT script for Vaadin7, maybe it will help a bit:
<target name="compile-widgetset" depends="init,resolve">
<delete includeEmptyDirs="true">
<fileset dir="${basedir}/WebContent/VAADIN/gwt-unitCache/" includes="**/*" defaultexcludes="no"/>
</delete>
<java classname="com.vaadin.tools.WidgetsetCompiler" failonerror="yes" fork="yes" maxmemory="600m">
<jvmarg value="-Xms512M"/>
<jvmarg value="-Xmx1024M"/>
<jvmarg value="-Xss8M"/>
<jvmarg value="-Djava.awt.headless=true" />
<arg value="-war"/>
<arg value="WebContent/VAADIN/widgetsets"/>
<arg value="${widgetset}"/>
<arg value="-logLevel"/>
<arg value="DEBUG"/>
<arg value="-style"/>
<arg value="OBF"/>
<classpath>
<pathelement path="${module.src.dir}"/>
<pathelement path="${module.build.dir}/WebContent/WEB-INF/classes" />
<pathelement path="${module.build.dir}/WebContent/WEB-INF/lib" />
<path refid="widgetset.path"/>
</classpath>
</java>
</target>
Compile instructions: https://vaadin.com/docs/v7/framework/clientside/clientside-compiling.html
I figured out using this url
https://github.com/canthony/simple-vaadin-7-compile-widgetset-ivy
I only added manifest tag to include dependecies in the META-INF/MANIFEST.MF file
<war destfile="${artifacts}/${warfilename}"
basedir="${workdir}"
webxml="${webroot}/WEB-INF/web.xml"
>
<manifest>
<attribute name="Dependencies" value="org.jboss.xnio, org.hibernate"/>
</manifest>
<lib dir="${webroot}/WEB-INF/lib" erroronmissingdir="no">
<include name="*.jar"/>
</lib>
<lib dir="${libraries}" erroronmissingdir="no">
<include name="*.jar"/>
</lib>
</war>

how to supply property file as class path

I am creating webservice using AXIS and running this using ANT script.
<target if="jars.ok" depends="make.repo" name="start.server">
<property name="port" value="7070"/>
<java fork="true" classname="org.apache.axis2.transport.http.SimpleHTTPServer">
<arg value="${build}/repo"/>
<classpath refid="axis2.class.path"/>
<arg value="-p${port}"/>
</java>
</target>
Setted classpath using
<path id="axis2.class.path">
<pathelement path="${java.class.path}"/>
<pathelement path="${maven.class.path}"/>
<fileset dir="${axis2.home}">
<include name="lib/*.jar"/>
<include name="resources/*.properties"/>
</fileset>
</path>
But i am getting error as
[java] log4j:WARN Please initialize the log4j system properly [SimpleHTTPServer]
What do I need to do to fix this issue, thanks a lot
You can not add Property files as classpath, just folders and Jar files.
So here include the whole resources folder:
pathelement path="${axis2.home}/resources"

Need to make a ant build file for eclipse project

I have a simple game implemented in eclipse. It consists of about 8 classes.
It is for my school assignment.
In the turn in specification, there is written:
"Send me all source codes, documentation and ant build file, which allows the project to be compiled and generate javadoc documentation".
I really do not understand how ant works. I googled some tutorials, but I cannot understand them either. I tried to generate build.xml file in eclipse, but the teacher said that this doesnt work either.
Could someone give me some simple steps or give me link to some really basic tutorial? Thanks for help.
This is the eclipse generated ant (export project as antbuildfile):
And it is kind of weird, because the class BasicPaint I deleted a long time ago.
<?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="Snakes_and_Adders">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<path id="Snakes_and_Adders.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="Snakes_and_Adders.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target name="BasicPaint">
<java classname="snakes_and_adders.BasicPaint" failonerror="true" fork="yes">
<classpath refid="Snakes_and_Adders.classpath"/>
</java>
</target>
<target name="Game">
<java classname="snakes_and_adders.Game" failonerror="true" fork="yes">
<classpath refid="Snakes_and_Adders.classpath"/>
</java>
</target>
<target name="NewGame">
<java classname="snakes_and_adders.NewGame" failonerror="true" fork="yes">
<classpath refid="Snakes_and_Adders.classpath"/>
</java>
</target>
<target name="PaintingExample">
<java classname="snakes_and_adders.PaintingExample" failonerror="true" fork="yes">
<classpath refid="Snakes_and_Adders.classpath"/>
</java>
</target>
Ant is used to perform tasks that are useful to build applications. You have tasks like <javac> <jar> etc.. To compile your classes and put them in a jar file.
I don't see why the build.xml generated file wouldn't work.. But you can take it as an example to understand how ant works. You can also adapt that build.xml file to make it work anywhere.
This tutorial looks well explained at first sight: http://www.javaworld.com/article/2076208/java-app-dev/automate-your-build-process-using-java-and-ant.html
I find that ant can be pretty complex easily, it'll take you time to understand it well but it's really doable.

ant build file terminating tag error

I am trying to run an ant build file for a java jar. For some reason, whenever I try to run ant run, it comes back and says, "Element of type target must be terminated by the matching </target> tag" This seems strange because I see that I do have a terminating tag for run. Would there be something else that could be causing this? Any help would be greatly appreciated!
<project>
<target name="compile">
<mkdir dir="build/classes"/>
<javac includeantruntime="false" srcdir="." destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/KnightsTour.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="PlayTour"/>
</manifest>
</jar>
</target>
<target name= "run" depends = "jar">
<java fork='yes' jar="build/jar/KnightsTour.jar"/>
<arg value="${rows}"/>
<arg value="${columns}"/>
<arg value="${attempts}"/>
</java>
</target>
<target name="view">
<exec executable="less">
<arg value="PlayTour.java" />
<arg value="KnightsTour.java" />
</exec>
</target>
<target name= "doc">
<mkdir dir="build/docs"/>
<javadoc sourcefiles="KnightsTour.java, PlayTour.java" destdir="build/docs"/>
</target>
</project>
<target name= "run" depends = "jar">
<java fork='yes' jar="build/jar/KnightsTour.jar"/>
<arg value="${rows}"/>
<arg value="${columns}"/>
<arg value="${attempts}"/>
</java>
</target>
You are closing the Java tag in the block above twice, first using /> in-line then writing </java>, which causes your error. This is what it looks like fixed:
<target name= "run" depends = "jar">
<java fork='yes' jar="build/jar/KnightsTour.jar" >
<arg value="${rows}"/>
<arg value="${columns}"/>
<arg value="${attempts}"/>
</java>
</target>
Whenever you suspect an XML validation error, you should use a free online XML validation utility to at least confirm that the structure of your file is correct. This is what I used to quickly locate your error: http://www.xmlvalidation.com/index.php?id=1&L=0

Groovy unable to resolve java class

i got a problem by executing groovy from an ant file.
In Eclipse with a launcher, everything works fine but wehn i run the ant file i got the following output:
Main.groovy: 71: unable to resolve class InitializeDatabase
[groovyc] # line 71, column 40. [groovyc] java.lang.Object
javaClassInstance = new InitializeDatabase()
[groovyc]
[groovyc] 1 error
InitializeDatabase is a java class in the same package..
public class InitializeDatabase {
public void test() {
System.out.println("Hello Groovy");
}
}
I guess the problem is located at the ant file:
<project name="tp" basedir="." default="dbsetup">
<target name="dbsetup">
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
<classpath>
<fileset dir="../files/lib/default" includes="*.jar" />
</classpath>
</taskdef>
<delete dir="bin" />
<mkdir dir="bin" />
<groovyc srcdir="src" destdir="bin" />
<java classname="groovy.ui.GroovyMain" dir="../.." fork="true" failonerror="true">
<classpath>
<fileset dir="../files/lib/default" includes="*.jar"/>
<pathelement location="bin"/>
</classpath>
<arg line="build/scripts/src/build/Main.groovy" />
</java>
</target>
</project>
Can someone help me please?
You need to include the javac task inside your groovyc one. Change:
<groovyc srcdir="src" destdir="bin" />
to
<groovyc srcdir="src" destdir="build">
<javac/>
</groovyc>
And it should work fine. As it says here:
Joint compilation means that the Groovy compilation will parse the
Groovy source files, create stubs for all of them, invoke the Java
compiler to compile the stubs along with Java sources, and then
continue compilation in the normal Groovy compiler way. This allows
mixing of Java and Groovy files without constraint.
...
The right way of working is, of course, to use a nested tag and all
the attributes and further nested tags as required.
Here is the final file which works great.
Thanks to tim_yates!
<target name="dbsetup">
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
<classpath>
<fileset dir="../files/lib/default" includes="*.jar" />
</classpath>
</taskdef>
<delete dir="bin" />
<mkdir dir="bin" />
<groovyc srcdir="src" destdir="bin">
<javac source="1.6" target="1.6" debug="on" />
</groovyc>
<java classname="groovy.ui.GroovyMain" dir="../.." fork="true" failonerror="true">
<classpath>
<fileset dir="../files/lib/default" includes="*.jar"/>
<pathelement location="bin"/>
</classpath>
<arg line="build/scripts/src/build/access/AccessDbSetup.groovy" />
</java>
</target>

Categories