Importing ZXing - missing core/build.xml - ant

I'm trying to import Google's ZXing.
I downloaded the latest release from https://code.google.com/p/zxing/downloads/detail?name=ZXing-2.2.zip&can=2&q=
From the cmd prompt I navigated to the root directory of the downloaded zxing and tried to execute
ant -f core\build.xml
PROBLEM :
Buildfile : build.xml does not exist!
Build failed
My zxing-2.2/core file contains :
src
test
pom.xml
Questions:
How to build a file that is missing?
Is it a problem from the zxing-2.2.jar I downloaded?

This problem happened to me too, I solved it by creating the build.xml file inside core folder
change name="whatever you want" in the second line, here it's "project"
code of build.xml:
<?xml version="1.0" encoding="utf-8" ?>
<project name="project" default="jar" basedir=".">
<target name="compile" description="Compile source">
<mkdir dir="bin" />
<javac srcdir="src" includes="**" destdir="bin"/>
<copy todir="bin">
<fileset dir="src" />
</copy>
</target>
<target name="jar" description="Package into JAR" depends="compile">
<jar destfile="project.jar" basedir="bin" compress="true" />
</target>
</project>
Run the build command again and see if it works.

Please do consider that you can always use the pom.xml to achieve the same. This is the method prescribed in the official zxing documentation
https://code.google.com/p/zxing/wiki/GettingStarted
The commands I have used are as follows:
cd core
mvn -DskipTests -Dgpg.skip=true install
That's it, you are done. Obviously, maven is to be installed before using the code

I tried the accepted answer, but unfortunately it not worked. Actually the jar was built successfully, but it was not built into the apk when Eclipse built the project. This was when i referenced ZXing as a library project. I managed to write an ant script which works, so i share it here:
<?xml version="1.0" encoding="utf-8" ?>
<project name="core" basedir="." default="dist" >
<property name="dist.dir" value="dist" />
<property name="src.dir" value="src" />
<property name="build.dir" value="bin" />
<target name="dist" depends="clean, package" />
<target name="clean" >
<delete dir="${build.dir}" />
</target>
<target name="init" >
<mkdir dir="${build.dir}" />
</target>
<target name="compile" >
<javac debug="off" destdir="${build.dir}" source="1.6" srcdir="${src.dir}" target="1.6" />
</target>
<target name="package" depends="init, compile" >
<jar basedir="${build.dir}" destfile="${dist.dir}/core.jar" />
</target>
</project>

If you just need the core.jar from zxing, you can skip that process and get the pre-built JARs from the GettingStarted wiki page
Core.jar is the library solution to integrate zxing in your app
(the other option is via Intent but BarcodeScanner.apk is needed)
For zxing2.2, you can obtain the core.jar from the zxing Maven repository here

Zxing 2.2 and above don't include core/build.xml
If the original file is necessary I recommend using Zxing 2.1, which can be found here:
https://code.google.com/p/zxing/downloads/detail?name=ZXing-2.2.zip&can=2&q=

Related

deleting object tree with ant using java language

When I do "make clean" it deletes all the object files , in C distributions.
What would be the command "make clean" when using ant, in Java distributions?
Java based build tools generaly build everything in target directory. ANT builds typically have a "clean" target that works as follows:
<target name="clean" description="Cleanup build files">
<delete dir="${build.dir}"/>
</target>
My advice is not to fight this one :-) It might look dumb but it's how more advanced tools like Maven work by default.
Example
I would typically declare some standard properties at the top of my build file:
<property name="src.dir" location="src/main/java"/>
<property name="build.dir" location="build"/>
<property name="dist.dir" location="${build.dir}/dist"/>
<property name="jar.main.class" value="org.demo.App"/>
<property name="jar.file" value="${dist.dir}/${ant.project.name}.jar"/>
Which are used to build my jar as follows:
<target name="compile" description="Compile code">
<mkdir dir="${build.dir}/classes"/>
<javac srcdir="${src.dir}" destdir="${build.dir}/classes" includeantruntime="false" debug="true" classpathref="compile.path"/>
</target>
<target name="build" depends="compile" description="Create executable jar archive">
<jar destfile="${jar.file}" basedir="${build.dir}/classes">
<manifest>
<attribute name="Main-Class" value="${jar.main.class}" />
</manifest>
</jar>
</target>
If you look carefully you'll notice everything ANT does is created under the "build" subdirectory.

Target Clean does not exist in the project dir

I have installed Ant in my centos 6.3 , installed location are
/opt/ant and also ANT_HOME env are same
I have created build.xml to test by deleting testdir. This directory exist in the /opt/ant/testdir like this.
build.xml
<?xml version="1.0"?>
<project name="testdir" default="all" basedir=".">
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="lib" value="lib"/>
<target name="all" depends="clean, compile" description="Builds the whole project">
<echo>Doing all</echo>
</target>
<target name="clean">
<echo message="Deleting bin/java ..." />
<delete dir="testdir/test" />
</target>
</project>
Using Command :-
ant -buildfile build.xml Clean
getting error:-
BUILD FAILED
Target "Clean" does not exist in the project "testdir".
Any suggestion to make it work?
You mis-spelt the target name ? 'Clean' as against 'clean' ??
I have found solution. I missed target="compile" block in build.xml.
<target name="compile">
<echo message="Compiling source code"/>
</target>
Run command :-
ant clean

Ant script fails to detect the javafx classes when compiling

I am using the Ant script to compile my source code. previously it was compiling perfectly . recently i added classes which uses javafx specific classes .after this ant is not compiling and it fails to find the javafx classes . i am using jdk 7 update 23 as javafx is inculded in the jdk, i cannot figure out why compilation fails ?.
below is my ant script.
<?xml version="1.0" encoding="UTF-8" ?>
<project name="client" basedir="." default="compile" >
<description>Client</description>
<property file="build.properties" />
<path id="classpath">
<fileset dir="${lib.dir}" includes="*.*"/>
</path>
<!-- Initialization -->
<target name="init" description="Prepare needed directories.">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${jar.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Cleanup -->
<target name="clean" description="Remove all files created by the build/test process.">
<delete dir="${classes.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${build.dir}" />
</target>
<!-- Compile application -->
<target name="compile" depends="init" >
<mkdir dir="${classes.dir}"/>
<javac source="1.7" target="1.7" srcdir="${src.dir}" destdir="${classes.dir}" debug="yes" includeantruntime="false" fork="true" memorymaximumsize="1200m" >
<classpath refid="classpath" />
</javac>
</target>
<path id="lib.lib">
<fileset dir="../lib">
<include name="**/*"/>
</fileset>
</path>
<pathconvert property="mf.classpath" pathsep=" lib/">
<path refid="lib.lib"/>
<flattenmapper/>
</pathconvert>
<!-- Java Archive -->
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/Client.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Class-Path" value="lib/${mf.classpath}"/>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
</target>
</project>
Suggested Solution
If you want to use ant with JavaFX, you should use Oracle's JavaFX ant tasks.
The JavaFX runtime is included with Java 7 and the Oracle JavaFX ant tasks are aware of it's location, so when you use the Oracle ant tasks, builds of projects referencing JavaFX work.
Why your current build fails
Compilation fails for your script because the JavaFX runtime (jfxrt.jar) is not on the default class path for Java 7.
For Java 8 the JavaFX runtime is on the class path.
You can still use plain ant without the Oracle JavaFX ant tasks to build your application (just by ensuring jfxrt.jar is on the class path for your build step), however use of the Oracle tasks is recommended as they will also appropriately package your application for distribution.
See also: Compile code using JavaFX 2.0 (using command line)

ANT Generated jar: is it a namespace issue?

I have a Eclipse-Java-Project with an ANT-build-file. This build file exports a jar of the project without compiling it. So I only export the sources.
<target name="jar">
<mkdir dir="/jar"/>
<jar destfile="/jar/my_test_jarfile.jar" basedir="/src" />
</target>
I use this generated jar in another eclipse java project and set the path to the jar in the build-path-settings of the project. The problem is that eclipse says it cannot resolve the namespace of the imported classes of the jar.
If I export the jar manually by right clicking on the project and then "Export" and putting the jar to the build path of the other project, everything works fine and there are no errors. So the question is now, what am I doing wrong?
So here is my solution. It seems that you have to compile the source first and then pack it into a jar. I don't give a guarantee that this jar is exactly the same like the one you get from eclipse when you do the right click thing and export etc.
But it works for me, there are no namespace errors any longer. so here is a minimum version of my ant targets:
<project default="run" basedir=".">
<property name="src.dir" value="src" />
<property name="classes.dir" value="bin" />
<property name="build.dir" value="build" />
<path id="libs">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${basedir}\${classes.dir}"/>
</path>
<target name="run">
<antcall target="compile"/>
<antcall target="jar"/>
</target>
<target name="compile">
<javac debug="true" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="libs" encoding="UTF-8" />
</target>
<target name="jar">
<jar destfile="${build.dir}/my_jar_file.jar" basedir="${classes.dir}">
</target>
</project>

Blackberry Apps - Importing a code-signed jar into an application project

I'm working on a library project that Blackberry Java developers can import into their projects. It uses protected RIM APIs which require that it be code-signed, which I have done. But, I can't get my Jar imported and working with a simple helloWorld app. I'm using the eclipse plug-in Blackberry-JDE.
EDIT : Solution found....
since I found the solution I removed the things I've tried, leaving only the solution ...
BUILDING THE SDK/Libary (use BB-ANT-TOOLS, either in eclipse or standalone)
steps:
A) I had to build my SDK's jar as an 'cldc' application not as a 'library'
project, using BB-ANT-TOOLS. This solved most of the issues I had above.
B) I then added an ANT task to take the resulting JAR from step A and
do the following:
unzip it,
edit the manifest file to remove the line "MicroEdition-Profile: MIDP-2.0" -- This line causes an error when you try to mark the jar for export.
then re-zipped the jar.
NOTE: I wrote a chopped down BB-ANT-TOOLS ant script to show how you could use
it to do these two steps above. The script is included below.
Consuming the SDK jar as an end-user or in your own project.
Then to integrate the jar in bb-eclipse you do the following:
A) Add the jar to the BuildPath
B) under "Java Build Path" on the "Order and Export" tab, Select the jar for
export. This causes rapc to build the jar into the COD file, so that you only
have one COD at the end.
now when a user builds this project the jar become integrated into the final
cod file, and it's very easy to deliver to the phone or sim.
<?xml version="1.0" encoding="UTF-8"?>
<project name="XXXXXMobileLib" default="full" basedir=".">
<description>
Description: Builds the BBLIB. Uses bb-ant-tools to build, sign and package for blackberry.
</description>
<taskdef resource="bb-ant-defs.xml" classpath="BIN/BB_ANT_lib/bb-ant-tools.1.x.x.jar" />
<property environment="env" />
<!-- User defined Vars -->
<property name="builderRoot" value="." />
<property name="SIG_PASSWORD" value="XXXXXXXXX" />
<property name="javaHome" value="${env.JAVA_HOME}" />
<echo>${javaHome}</echo>
<property name="jdehome" value="${env.BBJDE_HOME}\" />
<property name="simulator" value="${jdehome}\simulator" />
<property name="bin" value="${jdehome}\bin" />
<property name="releaseBuildOut" value="${builderRoot}\release_out\" />
<property name="srcBuildOut" value="${builderRoot}\srcBuild_out\" />
<property name="JarFixTemp" value="${builderRoot}\.tempZip\" />
<property name="buildVersion" value="${env.BUILD_VERSION}" />
<property name="application_id" value="com.XXXXX.foo.bar.${buildVersion}" />
<property name="application_name" value="XXXXX BBLIB v${buildVersion}" />
<property name="application_desc" value="XXXXX BBLIB v${buildVersion}" />
<property name="application_vendor" value="XXXXX" />
<property name="applicaiton_filename" value="XXXXXBBLIB${buildVersion}" />
<property name="applicaiton_srcs" value="${builderRoot}/src_in_location/" />
<property name="zipOutName" value="XXXXX-${buildVersion}BBLIB.zip" />
<property name="zipOutNameJavadocs" value="XXXXX-${buildVersion}BBLIBjavadoc.zip" />
<property name="jde.home" location="${jdehome}" />
<!--
MAIN ENTRY TARGET.
-->
<target name="full" depends="clean,javadoc,buildRIM,FixJarManifest,sign,distribute" />
<target name="FixJarManifest">
<tstamp/>
<mkdir dir="${JarFixTemp}"/>
<unzip src="${builderRoot}/release_out/${applicaiton_filename}.jar" dest="${JarFixTemp}"/>
<delete dir="${builderRoot}/release_out/${applicaiton_filename}.jar"/>
<!-- For some reason rapc puts this line into the manifest file, but it breaks the JDE plug-in when you try to
set the jar for export. Giving an error like this "Project {0} missing......"
To avoid having an empty line in the manifest, Im just injecting a new attribute BuildTime-->
<replace file="${JarFixTemp}/META-INF/MANIFEST.MF" token="MicroEdition-Profile: MIDP-2.0" value="Build-Time: ${DSTAMP}-${TSTAMP}"/>
<zip destfile="${builderRoot}/release_out/${applicaiton_filename}.jar"
basedir="${JarFixTemp}"
/>
<delete dir="${JarFixTemp}"/>
</target>
<!-- Cleanup any existing files in the outdir -->
<target name="clean">
<delete>
<fileset dir="${releaseBuildOut}" includes="**" />
</delete>
</target>
<!-- Generate the Javadocs -->
<target name="javadoc">
<javadoc access="public" destdir="${releaseBuildOut}/JavaDocs" author="true" version="true" use="true" defaultexcludes="yes" excludepackagenames="net.rim.*" windowtitle="FOO_BAR">
<fileset dir="${applicaiton_srcs}/XXXXXMobileLib">
<include name="src/**/*.java" />
</fileset>
</javadoc>
<zip destfile="${releaseBuildOut}/${zipOutNameJavadocs}" basedir="${releaseBuildOut}/JavaDocs" />
<delete dir="${releaseBuildOut}/JavaDocs"/>
</target>
<target name="buildRIM" description="Builds Project">
<rapc jdehome="${jdehome}" jdkhome="${javaHome}" destdir="${releaseBuildOut}" output="${applicaiton_filename}" quiet="false">
<!-- Building as a cldc applicaiton, so it can be packaged up with our final cod, as a single cod -->
<jdp type="cldc"
title="${application_desc}"
vendor="${application_vendor}"
version="${buildVersion}"
description="${application_desc}"
arguments=""
systemmodule="false"
runonstartup="false"
startuptier="7"
ribbonposition="0">
</jdp>
<src>
<fileset dir="${applicaiton_srcs}/MobileLib">
<include name="src/**/*.java" />
</fileset>
</src>
</rapc>
</target>
<target name="sign" depends="clean,buildRIM">
<sigtool password="${SIG_PASSWORD}">
<fileset dir="${releaseBuildOut}" includes="*.cod" />
</sigtool>
<echo>Contents of the signingtool's logfile: </echo>
<echo file="LogFile.txt" />
</target>
<!-- build and distribute the jar -->
<target name="distribute" depends="buildRIM" description="generate the distribution">
<alx destdir="${releaseBuildOut}" filename="${applicaiton_filename}.alx">
<application id="${application_id}" name="${application_name}">
<codset>
<fileset dir="${releaseBuildOut}" includes="*.cod" />
</codset>
</application>
</alx>
<!-- Create release zip -->
<delete file="${releaseBuildOut}/${zipOutName}" />
<zip destfile="${releaseBuildOut}/${zipOutName}">
<!-- zip up the BB jar and drop it for distribution -->
<zipfileset dir="${releaseBuildOut}" includes="**/*.jar" />
</zip>
<move todir="${releaseBuildOut}/UNUSED_BUILD_OUTPUT_FILES/"><!-- move unwanted files, leaving the zip behind -->
<fileset dir="${releaseBuildOut}">
<include name="**/*.*"/>
<exclude name="**/*.zip"/>
</fileset>
</move>
</target>
</project>
I have used your steps A & B to create a 'library' - thanks.
The latest Eclipse plugin for Blackberry (1.3.0.201102031007-19) has a "Blackberry | Package Project" command. I used this to create the jar file (it put it in a 'deliverables' folder in the project).
I then changed the manifest as you suggest to remove MIDP line (which apparently is a known bug). Finally, I followed the steps to add and deploy the lib to my project. (These, btw, are the same steps to adding the Banner / advertising library - very easy.)
I too have a stand-alone / external build script process that uses bb-ant-tools. I recently added the 'external library jar' feature to accommodate this. But using the new feature in Eclipse makes me question if I need to maintain my command-line build scripts as the GUI now does it for me.
The key for me was to switch the build of my library project to a "Blackberry Application" (e.g. CDLC app) as per your instructions. With it set as a 'Library' I was getting that "eviscerated" error.
Thanks for your post.

Resources