CodenameOne Problems on Ant-Build - ant

I Would like to ask for some help for my codenameone build.
I can't figure out what causes this error.
The Error description everything i recieved :
build.xml:78: Compile failed; see the compiler error output for details.
My Context around line 78 Build.xml File:
The error happends by the classpath.
<target name="-pre-compile" depends="-cn1-compile-css">
<echo>Compile is forcing compliance to the supported API's/features for maximum device compatibility. This
allows smaller
code size and wider device support
</echo>
<mkdir dir="build/tmp"/>
<javac destdir="build/tmp"
encoding="${source.encoding}"
source="1.8"
target="1.8"
bootclasspath="lib/CLDC11.jar" excludes="${excludes}"
classpath="${javac.classpath}:${build.classes.dir}">
<src path="${src.dir}"/>
<withKotlin>
<compilerarg value="-no-stdlib"/>
<compilerarg value="-no-reflect"/>
<compilerarg value="-no-jdk"/>
</withKotlin>
</javac>
</target>

Related

exist-db : Issues with ant task xdb:adduser or xdb:users : no such handler

I'm using ant scripts for initializing my exist-db.
But, I have this script below (dummy version) which is working in my local platform and not on my procution one. As I'm not the one who handle the configuration of this database, I don't know where to look in the conf to fix this.
Here is the script (which is just trying to add a new user) :
<project basedir="." default="default" name="ANTProject">
<property file="load.properties"/>
<path id="classpath.core">
<fileset dir="${path}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${path}\exist.jar"/>
<pathelement path="${path}\exist-optional.jar"/>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<target name="default">
<echo message="Création du compte ${login}"/>
<xdb:adduser xmlns:xdb="http://exist-db.org/ant"
uri="xmldb:exist://${exist.uri}/exist/xmlrpc/db"
name="${login}" secret="${password}" primaryGroup="${user.group}" user="${root.login}"
password="${root.password}"/>
</target>
</project>
I get this error message :
XMLDB exception caught: No such handler: Default.setUser
I get the same thing if I use xdb:users task, but the xdb:store is working well... I'm running exist 2.1, in both my local and production plateform, and as already told, same scripts working well on local one...
I guess, it's something about the exist configuration, but I didn't find anything on enabling this tasks in the documentation.
If someone could help...
Ok, I got it.
Just for completeness, It was an issue on jar librairies. It seems I used ones which support xdb:store, but not others tasks (didn't find any release version of this)...
This ant depandancies is quite tricky and It's hard to know what your jars offer...

groovyc ant task fails with fork="true"

When I run groovyc without the fork option, it works fine. But with fork="true" it fails with an error message:
Error: Could not find or load main class org.codehaus.groovy.ant.FileSystemCompilerFacade
What is wrong here?
Ant task:
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="test.path" />
<groovyc fork="true" srcdir="../myproject/src-test" destdir="${build.test.dir}">
<javac debug="true" source="1.7" target="1.7" >
<compilerarg value="-XX:-UseSplitVerifier"/>
</javac>
</groovyc>
EDIT:
test.path contains a groovy jar:
(...):/home/pkalinow/(..)/groovy-all-1.8.6.jar:(...)
The classpathref="test.path" must be specified in both <taskdef> and <groovyc> invocations when groovyc is forked.
I cannot find any confirmation in the documentation, but it seems, that only non-forking groovyc is inheriting classpath from taskdef.

ANT: ways to include libraries and license issues

I have been trying to use Ant to compile and ready a project for distribution. I have encountered several problems along the way that I have been finally able to solve but the solution leaves me very unsatisfied. First, let me explain the set-up of the project and its dependencies.
I have a project, lets call it Primary which depends on a couple of libraries such as the fantastic Guava. It also depends on another project of mine, lets call it Secondary. The Secondary project also features some dependencies, for example, JDOM2. I have referenced the Jar I build with Ant in Primary.
Let me give you the interesting bits of the build.xml so you can get a picture of what I am doing:
<project name="Primary" default="all" basedir=".">
<property name='build' location='dist' />
<property name='application.version' value='1.0'/>
<property name='application.name' value='Primary'/>
<property name='distribution' value='${application.name}-${application.version}'/>
<path id='compile.classpath'>
<fileset dir='libs'>
<include name='*.jar'/>
</fileset>
</path>
<target name='compile' description='Compile source files.'>
<javac includeantruntime="false" srcdir="src" destdir="bin">
<classpath refid='compile.classpath'/>
</javac>
<target>
<target name='jar' description='Create a jar file for distribution.' depends="compile">
<jar destfile='${build}/${distribution}.jar'>
<fileset dir="bin"/>
<zipgroupfileset dir="libs" includes="*.jar"/>
</jar>
</target>
The Secodnary project's build.xml is nearly identical except that it features a manifest as it needs to run:
<target name='jar' description='Create a jar file for distribution.' depends="compile">
<jar destfile='${dist}/${distribution}.jar' basedir="${build}" >
<fileset dir="${build}"/>
<zipgroupfileset dir="libs" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="lu.tudor.ssi.kiss.climate.ClimateChange"/>
</manifest>
</jar>
</target>
After I got it working, trying for many hours to not include that dependencies as class files but as Jars, I don't have the time or insight to go back and try to figure out what I did wrong. Furthermore, I believe that including these libraries as class files is bad practice as it could give rise to licensing issues while not packaging them and merely including them in a directory along the build Jar would most probably not (And if it would you could choose not to distribute them yourself).
I think my inability to correctly assemble the class path, I always received NoClassDefFoundError for classes or libraries in the Primary project when launching Second's Jar, is that I am not very experienced with Ant. Would I require to specify a class path for both projects? Specifying the class path as . should have allowed me to simply add all dependencies to the same folder as Secondary's Jar, should it not?
You may use the MANIFEST.MF "Class-Path: " to cross-reference your jars.
If they are all in the same directory this will probably work as follows (using it in both projects!):
<target name='jar' description='Create a jar file for distribution.' depends="compile">
<pathconvert property="manifest.classpath" pathsep=" ">
<path refid="compile.classpath" />
<flattenmapper />
</pathconvert>
<jar destfile='${build}/${distribution}.jar'>
<fileset dir="bin"/>
<manifest>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
</jar>
</target>
This way you can tell the java runtime environment that your jar needs others to work, expecting them to be in the same directory as the jar you are trying to run.
As a result your primary.jar should have secondary.jar in it's classpath and secondary.jar should have guava.jar in it's classpath.
Another way to create the string may be ants manifestclasspath task (https://ant.apache.org/manual/Tasks/manifestclasspath.html) that can handle subdirectories.
If you are goin to use more and more libraries, you may want to have a closer look at ivy or even maven.

JPAAnnotationProcessor processing files excluded by ant

I'm not sure whether this is a question concerning ant or the JPAAnnotationProcessor of QueryDSL.
I have a following target in the build.xml:
<target name="querydsl" depends="-prepare">
<javac srcdir="${src.java.home}" classpathref="compile.classpath" includeantruntime="false">
<include name="de/foo/bar/database/model/**"/>
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="com.mysema.query.apt.jpa.JPAAnnotationProcessor"/>
<compilerarg value="-s"/>
<compilerarg value="${src.java.generated.home}"/>
</javac>
</target>
and I only want the classes located under de/foo/bar/database/model/ to be processed.
When I execute ant querydsl I get compile errors from classes that are located outside of the ant include parameter, e.g.
[javac] C:\projects\main\cxlBackend\src\main\java\de\foo\bar\database\service\company\CompanyServiceImpl.java:96: cannot find symbol
[javac] symbol : class QAccount
I tried to explicitly exclude this class with
<exclude name="de/foo/bar/database/service/company/CompanyServiceImpl.java"/>
but I'm still getting the same error.
Edit: At the beginning, ant writes out:
[javac] Compiling 267 source files
That's the exact number of classes in the de/foo/bar/database/model/ directory.
These warnings are printed by javac since the Q-classes are not yet available.
According to the javac docs you can suppress the warnings with the -nowarn flag.
The problem went away after an upgrade to Java 7 (from Java 6).

Ant: javac with proc:only from Ant?

Is there any way to enforce javac task to invoke only annotation processing, without compilation. -proc:only javac option is supposed to enforce such behaviour, according to javac documentation.
But the following snippet of ant buildfile:
<target name="apt">
<javac srcdir="src" destdir="bin" includeantruntime="false">
<compilerarg value="-proc:only"/>
</javac>
</target>
Compiles project anyway. I experimented with other <compilerarg> tag versions (e.g. line instead of value) but nothing helped.
Avoid specifying the "destdir" attribute of the task, or use an empty directory as a destination for class files. The Ant "javac" task will then look for the class files either in the base directory (if you leave "destdir" unset) or in the empty directory. Because it will not find the classs files there, it will not exclude the potentially up-to-date sources from the compilation and execute "javac" on the sources from the directory specified in the "srcdir" attribute.
Your code would therefore look like this:
<target name="apt">
<javac srcdir="src" includeantruntime="false">
<compilerarg value="-proc:only" />
</javac>
</target>
or, if you use the empty directory approach, like this:
<target name="apt">
<mkdir dir="empty" />
<javac srcdir="src" destdir="empty" includeantruntime="false">
<compilerarg value="-proc:only" />
</javac>
</target>
The second approach is slightly more complex but a bit more clean. Usually your project will have an output directory where you put compiled classes and packaged jars, so adding an extra empty directory there would not hurt. As of Ant version 1.9.4, I did not find any other way to do annotation processing from Ant independently of compilation, even though a simple "force" attribute in the "javac" task could solve this problem.

Resources