Note that there are some explanatory texts on larger screens.

plurals
  1. POAnt can't find XPathExpressionException when run from Java but does on the command line when building an Android App
    primarykey
    data
    text
    <p>Currently, I am trying to build an android application using Ant on a GlassFish server.</p> <p>My current build.xml will build fine when I run <code>ant debug</code> or <code>ant release</code> from the command line, but when I attempt to build it via Java it throws an exception and tells me it can't find the class: javax/xml/xpath/XPathExpressionException</p> <p>The relevant part of the error message is:</p> <pre><code>C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\ant\build.xml:109: taskdef A class needed by class com.android.ant.GetTypeTask cannot be found: javax/xml/xpath/XPathExpressionException using the classloader AntClassLoader[C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\anttasks.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\common.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\guava-tools.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\sdklib.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\layoutlib_api.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\commons-compress-1.0.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\httpclient-4.1.1.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\httpcore-4.1.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\httpmime-4.1.1.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\commons-logging-1.1.1.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\commons-codec-1.4.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\dvlib.jar;C:\androidsdk\adt-bundle-windows-x86_64\sdk\tools\lib\manifmerger.jar] </code></pre> <p>Line 109 of the android build.xml is: <code>&lt;taskdef resource="anttasks.properties" classpathref="android.antlibs" /&gt;</code></p> <p>Which refers to a file within the anttasks.jar that has an entry in it for xpath.</p> <h2>Build Files</h2> <p>The build file for the app looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;project name="2007_doc2" default="help"&gt; &lt;property file="local.properties"/&gt; &lt;property file="ant.properties"/&gt; &lt;property environment="env"/&gt; &lt;condition property="sdk.dir" value="${env.ANDROID_HOME}"&gt; &lt;isset property="env.ANDROID_HOME"/&gt; &lt;/condition&gt; &lt;loadproperties srcFile="project.properties"/&gt; &lt;!-- quick check on sdk.dir --&gt; &lt;fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." unless="sdk.dir" /&gt; &lt;import file="custom_rules.xml" optional="true"/&gt; &lt;import file="${sdk.dir}/tools/ant/build.xml"/&gt; &lt;/project&gt; </code></pre> <p>My ant.properties file is empty, the local.properties file points correctly to the SDK, and the only thing within the project.properties file is: <code>target=android-10</code></p> <h2>The Java Code</h2> <p>The Java code I am using to try to run Ant is all within one class and looks like this (shortened for saving space):</p> <pre><code>setupSDK(dir); Project project = new Project(); project.setUserProperty("ant.file", buildFile.getAbsolutePath()); project.setBaseDir(dir); DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); consoleLogger.setMessageOutputLevel(Project.MSG_INFO); project.addBuildListener(consoleLogger); project.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); project.addReference("ant.projectHelper", helper); helper.parse(project, buildFile); project.executeTarget(project.getDefaultTarget()); // build </code></pre> <p><code>setupSDK(dir)</code> creates the local.properties file on the fly using either a JVM flag or the environment variable ANDROID_HOME (and works correctly).</p> <h2>That's it</h2> <p>That's all the relevant stuff I believe. I am running this on a brand new Windows 8 machine with the 64bit JDK but it has the same problem when run on a Windows 7 machine running a 32bit JVM.</p> <p>As I said above, it works when I run <code>ant release</code> or <code>ant debug</code> on the command line so I am at a loss as to why it's not working from Java.</p> <h2>Update</h2> <p>After some testing it seems like it actually works from Java when not run on a GlassFish server. Anyone have any ideas? </p> <p>Thanks, Lyndon</p> <h2>Another Update</h2> <p>One of my work colleagues has suggested it could be to do with scope and the fact I am trying to load classes outside of the GlassFish domain which seems like it might be the reason.</p> <h2>Update</h2> <p>This does seem to be the case although I am not entirely sure how to solve it. I just found that when running outside of Glassfish the classpath Ant is given is very long and includes all the glassfish modules (I think) along with the correct runtimes from my JDK (that includes rt.jar). </p> <p>Whereas when run on glassfish the only thing on the java classpath is: C:\Program Files\glassfish-3.1.2.2\glassfish\modules\glassfish.jar</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload