Page 1 of 1

Creating a jar in the development environment

PostPosted: Mon May 11, 2009 6:26 pm
by Leigh
This is my first time using Maven and Ant. How does one build a local jar in the development environment?

I tried running "mvn package" and then "dist" in build.xml. But both return compilation errors. I am guessing I either have the wrong tool(s) or my configuration just needs tweaking.

(Sorry if this question was answered previously. My searches did not turn up any hits on this question).

results: mvn package
Code: Select all
...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

C:\eclipse\workspace\docx4j\src\test\java\org\docx4j\listnumbering\ind\ListNumbe
rIndTest.java:[84,25] cannot find symbol
symbol  : class XmlPackage
location: package org.docx4j.convert.in

C:\eclipse\workspace\docx4j\src\test\java\org\docx4j\listnumbering\ind\ListNumbe
rIndTest.java:[84,75] cannot find symbol
symbol  : class XmlPackage
location: package org.docx4j.convert.in
...


results: "dist" in build xml
Code: Select all
Buildfile: C:\eclipse\workspace\docx4j\build.xml
clean:
   [delete] Deleting directory C:\eclipse\workspace\docx4j\bin
init:
    [mkdir] Created dir: C:\eclipse\workspace\docx4j\bin
     [copy] Copying 22 files to C:\eclipse\workspace\docx4j\bin
build-project:
     [echo] docx4j: C:\eclipse\workspace\docx4j\build.xml
    [javac] Compiling 776 source files to C:\eclipse\workspace\docx4j\bin
    [javac] C:\eclipse\workspace\docx4j\src\main\java\org\docx4j\Dom4jUtils.java:25: package org.apache.log4j does not exist
    [javac] import org.apache.log4j.Logger;
    [javac]                        ^
    [javac] C:\eclipse\workspace\docx4j\src\main\java\org\docx4j\Dom4jUtils.java:27: package org.dom4j does not exist
    [javac] import org.dom4j.DocumentException;
...

Re: Creating a jar in the development environment

PostPosted: Tue May 12, 2009 1:52 am
by jason
Hi Leigh

You should use ant dist to create a jar, not maven. At present, we only use maven for dependency management (in my case, via the m2eclipse plugin - see http://dev.plutext.org/trac/umbrella/wiki/MavenEclipse). It would probably be simple enough to ensure maven can create a jar from the command line, but I haven't gotten around to this. Perhaps if someone out there has this set up, they could post the necessary changes?

As far as getting ant dist working for you is concerned, in build.xml, make sure the following property is correct:

Code: Select all
<property name="m2Repository" value="../../.m2/repository"/>


and that you have used maven to download all the necessary dependencies.

After that, it should work.

For reference, here are the jars I am building against.

Code: Select all
    <path id="Maven Dependencies.libraryclasspath">
        <pathelement location="${m2Repository}/junit/junit/4.4/junit-4.4.jar"/>       
        <pathelement location="${m2Repository}/javax/jcr/jcr/1.0/jcr-1.0.jar"/>
        <pathelement location="${m2Repository}/log4j/log4j/1.2.13/log4j-1.2.13.jar"/>
        <pathelement location="${m2Repository}/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
        <pathelement location="${m2Repository}/xml-apis/xml-apis/1.3.03/xml-apis-1.3.03.jar"/>
        <pathelement location="${m2Repository}/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
        <pathelement location="${m2Repository}/commons-io/commons-io/1.3.1/commons-io-1.3.1.jar"/>
        <pathelement location="${m2Repository}/jdom/jdom/1.0/jdom-1.0.jar"/> <!--  for commons-vfs -->
       <pathelement location="${m2Repository}/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"/>
        <pathelement location="${m2Repository}/org/apache/xmlgraphics/xmlgraphics-commons/1.3.757686/xmlgraphics-commons-1.3.757686.jar"/>
        <pathelement location="${m2Repository}/org/apache/poi/hwpf/3.4.0/hwpf-3.4.0.jar"/>
        <pathelement location="${m2Repository}/com/topologi/diffx/0.61/diffx-0.61.jar"/>
        <pathelement location="${m2Repository}/com/lowagie/itext-unsigned/2.0.8/itext-unsigned-2.0.8.jar"/>       
        <pathelement location="${m2Repository}/xalan/xalan-patched/2.7.0/xalan-patched-2.7.0.jar"/>
        <pathelement location="${m2Repository}/pdf-renderer/pdf-renderer/0.2009.0324/pdf-renderer-0.2009.0324.jar"/>
        <pathelement location="${m2Repository}/org/jvnet/jaxb2_commons/ppp/parent-pointer-plugin/1.0/parent-pointer-plugin-1.0.jar"/>
        <pathelement location="${m2Repository}/xhtmlrenderer/minium/0.1/minium-0.1.jar"/>
        <pathelement location="${m2Repository}/xhtmlrenderer/core-renderer/R8pre2/core-renderer-R8pre2.jar"/>
        <pathelement location="${m2Repository}/org/apache/avalon/framework/avalon-framework-api/4.3.1/avalon-framework-api-4.3.1.jar"/>
        <pathelement location="${m2Repository}/org/apache/avalon/framework/avalon-framework-impl/4.3.1/avalon-framework-impl-4.3.1.jar"/>
        <pathelement location="${m2Repository}/docx4j/fop-patched/0.95.756434/fop-patched-0.95.756434.jar"/>
        <pathelement location="${m2Repository}/org/apache/commons/commons-vfs-patched/1.9.1/commons-vfs-patched-1.9.1.jar"/>
    </path>



cheers

Jason

Re: Creating a jar in the development environment

PostPosted: Tue May 12, 2009 5:19 am
by Leigh
Jason,

Excellent. Fixing the m2Repository path, and your tip about resolving the com.sun.xml.bind.marshaller.NamespacePrefixMapper issue with jdk 1.6, did the trick. My first jar created with Ant. I am ridiculously excited ;)

For anyone else on windows, when I originally ran mvn install the repository defaulted to C:\Documents and Settings\username\.m2\repository. So setting m2Repository to that path resolved the problem. I also found you could set java.endorsed.dirs in build.xml with <compilerarg>. Just add a property.

* using ant 1.7, jdk 1.6.0_13 (absolute paths are for clarity)
Code: Select all
    <property name="endorsedJarDirec" value="C:/eclipse/workspace/docx4j/endorsedJars" />
    ...
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac  bootclasspathref="jre.libs" includeJavaRuntime="yes"
           debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
            <src path="src/main/java"/>
            <classpath refid="docx4j.classpath"/>
           <compilerarg value="-Djava.endorsed.dirs=${endorsedJarDirec}"/>
        </javac>
    </target>


Thanks a lot for your help!