I am running a simple Ant script for SonarQube and have the following error:
FileNotFoundException: C:\Users\c5187668\sap\simpleAnt.sonar\batch\sonar-batch-maven-compat-5.1.2.jar|99845a2f47eaef85b29978725f82c50c"
SonarQube Server Version 5.1.2
Apache Ant(TM) version 1.9.6 compiled on June 29 2015
Sonar Ant Task version: 2.0
Java 1.6 - so, we cannot use modern version of Sonar Ant.
Can it be fixed somehow? Any ideas?
The Ant script:
<project name="sonar build" default="Sonar" basedir="." xmlns:sonar="antlib:org.sonar.ant">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="sonar-ant-task.jar"/>
</taskdef>
<!-- Out-of-the-box those parameters are optional -->
<property name="sonar.jdbc.url" value="dbc:mysql://?????:3306/sonardb?useUnicode=true;characterEncoding=utf8" />
<property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" />
<property name="sonar.jdbc.username" value="?????" />
<property name="sonar.jdbc.password" value="?????" />
<!-- Additional Sonar configuration (PMD need 1.5 when using annotations)-->
<property name="sonar.java.source" value="1.6"/>
<property name="sonar.java.target" value="1.6"/>
<property name="sonar.projectName" value="SonarBuild"/>
<property name="sonar.projectVersion" value="2.0" />
<!-- SERVER ON A REMOTE HOST -->
<property name="sonar.host.url" value="http://??????" />
<target name="Sonar">
<sonar:sonar />
</target>
I got the following error:
BUILD FAILED C:\Users\c5187668\sap\simpleAnt\build.xml:17:
java.lang.IllegalStateException: Fail to download libraries from
server
at org.sonar.runner.Bootstrapper.downloadBatchFiles(Bootstrapper.java:166)
at org.sonar.runner.Bootstrapper.createClassLoader(Bootstrapper.java:89)
at org.sonar.runner.Runner.createClassLoader(Runner.java:229)
at org.sonar.runner.Runner.execute(Runner.java:151)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:93)
at org.sonar.ant.SonarTask.execute(SonarTask.java:75)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:853)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112) Caused
by: java.lang.IllegalStateException: Fail to download the file:
http://???????/batch/sonar-batch-maven-compat-5.1.2.jar|99845a2f47eaef85b29
978725f82c50c
at org.sonar.runner.Bootstrapper.remoteContentToFile(Bootstrapper.java:115)
at org.sonar.runner.Bootstrapper.downloadBatchFiles(Bootstrapper.java:161)
... 22 more Caused by: java.io.FileNotFoundException: C:\Users\c5187668\sap\simpleAnt\.sonar\batch\sonar-batch-maven-compat-5.1.2.jar|99845a2f47eaef85b29978725f82c50c
(The filename, directory name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at org.sonar.runner.Bootstrapper.remoteContentToFile(Bootstrapper.java:109)
... 23 more
Total time: 0 seconds
P.S. by question marks ????? I hide real server name and credentials.
Your Ant Task version (2.0) is not compatible with your SonarQube version. This compatibility matrix shows that v2.2 is a minimum requirement since SonarQube 3.7 (2.4 being the best choice for SonarQube 4.5+).
You should upgrade your SonarQube Scanner for Ant and also use a supported version of Java.
You told Ant that your SonarQube server is running at http://?????? , the script therefore fails (quite understandably) to download the resources it needs from the server.
Fix this:
<property name="sonar.host.url" value="http://??????" />
The value should be the URL you use to browse your SonarQube server's homepage.
P.S.: you'll also have to fix sonar.jdbc.username and sonar.jdbc.password
Related
So I made an ANT target to deploy our app to Tomcat on a remote development server. The ANT deploy to tomcat target works 100% perfect on a local Tomcat instance. When I deploy to the remote server I get a fat 500 error but the application actually deploys to the server and we can view and use it just fine as if there were no errors.
Super cool that it works but the 500 error causes the ANT target to say the build failed. If ANT says the build failed, so will Hudson our build server, which means we will have sad red dots instead of happy green ones.
We are using the latest and greatest ANT with Tomcat v9.
Below is the error I get when I execute my "ant deploy-dev" target.
[username#localhost app.directory]$ ant deploy-dev
Buildfile: /home/username/git/app.directory/build.xml
Trying to override old definition of datatype resources
deploy-dev:
[echo] Deploying app to: https://dev.myapp.com
BUILD FAILED
/home/username/git/app.directory/build.xml:73: The following error occurred while executing this line:
/home/username/git/app.directory/build.xml:146: java.io.IOException: Server returned HTTP response code: 500 for URL: https://dev.myapp.com/manager/text/deploy?path=%2Fmy-app%2F
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:254)
at org.apache.catalina.ant.DeployTask.execute(DeployTask.java:194)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:854)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
Total time: 3 minutes 3 seconds
To get an idea of what is running, here is the important parts of the ANT build.xml.
<property environment="env"/>
<property file="build.properties"/>
<!-- Import -->
<import file="${env.CATALINA_HOME}/bin/catalina-tasks.xml" optional="true"/>
<!-- The deploy to Tomcat target -->
<target name="deploy-local" description="Deploy the app to local Tomcat">
<tomcat-deploy base-url="${url.base.local}"/>
</target>
<target name="deploy-dev" description="Deploy the app to dev Tomcat">
<tomcat-deploy base-url="${url.base.dev}"/>
</target>
<target name="undeploy-local" depends="stop-local" description="Undeploy the app from local Tomcat">
<tomcat-undeploy base-url="${url.base.local}"/>
</target>
<target name="undeploy-dev" depends="stop-dev" description="Undeploy the app from dev Tomcat">
<tomcat-undeploy base-url="${url.base.dev}"/>
</target>
<target name="stop-local" description="Stop the app on local Tomcat">
<tomcat-stop base-url="${url.base.local}"/>
</target>
<target name="stop-dev" description="Stop the app on dev Tomcat">
<tomcat-stop base-url="${url.base.dev}"/>
</target>
<macrodef name="tomcat-deploy">
<attribute name="base-url"/>
<sequential>
<echo>Deploying app to: #{base-url}</echo>
<deploy url="#{base-url}/manager/text" username="${username}" password="${password}"
path="/${app.name}" war="file:${war.path}.war"/>
</sequential>
</macrodef>
<macrodef name="tomcat-undeploy">
<attribute name="base-url"/>
<sequential>
<echo>Un-deploying app from: #{base-url}</echo>
<undeploy
failonerror="no"
url="#{base-url}/manager/text"
username="${username}"
password="${password}"
path="/${app.name}"
/>
</sequential>
</macrodef>
<macrodef name="tomcat-stop">
<attribute name="base-url"/>
<sequential>
<echo>Stopping the app at: #{base-url}</echo>
<stop url="#{base-url}/manager/text" username="${username}"
password="${password}" path="/${app.name}" />
</sequential>
</macrodef>
Anyone have any idea why the deploy to remote works but still returns an error? The error I get is kind of vague so I don't know what I could do to debug it.
The problem was the server was taking too long to deploy the app. Somewhere the Tomcat Deploy target is waiting for a response from the server saying the app was deployed. Unfortunately the only error is the 500 and there is nothing else to go on.
The solution, I simply re-installed Tomcat with Version 9, up from 8, and everything turned on much faster and the build was successful.
I can't really say this is the best answer but I got everything working.Hopefully someone has a better solution one day.
I am using jdk-1.7.0_51, Sonarqube-4.5.1 and Ant-1.9.1. I get this below error when target : sonar is invoked through Ant step in Jenkins. The same is the case with Ant-1.8.4.
Buildfile: /cip/jenkins/workspace/test/build.xml
[echo] the current time is 18/01/2016_14:06:37:037
sonar:
[sonar:sonar] Apache Ant(TM) version 1.8.4 compiled on May 22 2012
[sonar:sonar] Sonar Ant Task version: 1.0
[sonar:sonar] Loaded from: file:/cip/opt/apache-ant-1.8.4/lib/sonar-ant-task-1.0.jar
[sonar:sonar] Sonar work directory: /cip/jenkins/workspace/test/.sonar
[sonar:sonar] Sonar server: http://localhost:9000/sonar
[sonar:sonar] Sonar version: 4.5.1
BUILD FAILED
/cip/jenkins/workspace/test/build.xml:1007: org.sonar.batch.bootstrapper.BootstrapException: java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:9000/sonar/batch/
at org.sonar.batch.bootstrapper.Bootstrapper.downloadBatchFiles(Bootstrapper.java:164)
at org.sonar.batch.bootstrapper.Bootstrapper.createClassLoader(Bootstrapper.java:87)
at org.sonar.ant.SonarTask.createClassLoader(SonarTask.java:180)
at org.sonar.ant.SonarTask.execute(SonarTask.java:151)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:9000/sonar/batch/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
at java.net.URLConnection.getContent(URLConnection.java:748)
at org.sonar.batch.bootstrapper.Bootstrapper.remoteContent(Bootstrapper.java:123)
at org.sonar.batch.bootstrapper.Bootstrapper.downloadBatchFiles(Bootstrapper.java:156)
... 19 more
Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
when accessing http://localhost:9000/sonar/batch/ i get
{"errors":[{"msg":"Bad filename: "}]}
my build.xml has
<property environment="env"/>
<property name="sonar.host.url" value="${env.SONAR_HOST}"/>
<property name="sonar.jdbc.url" value="${env.SONAR_JDBC}"/>
<property name="sonar.jdbc.driverClassName" value="${env.JDBC_DRIVER}"/>
<property name="sonar.jdbc.username" value="${env.SONAR_USR}"/>
<property name="sonar.jdbc.password" value="${env.SONAR_PWD}"/>
<property name="sonar.login" value="${env.UI_USR}"/>
<property name="sonar.password" value="${env.UI_PWD}"/>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="/cip/opt/apache-ant-1.8.4/lib"/>
</taskdef>
<target name="sonar">
<property name="sonar.sources" value="src"/>
<property name="sonar.projectName" value="test"/>
<sonar:sonar workDir="src/temp" key="test:test" version="Trunk"/>
</target>
My question is similar to Sonar Ant task execution error , but this is not answered.
Earlier it was working fine with sonar 4.0 , but now i face this error.
Is this because of sonar-ant-task-1.0.jar? isnt this compatible with sonarqube 4.5.1? i have used sonar-ant-task-2.0.jar but i get different error.
sonar:
BUILD FAILED
/cip/jenkins/workspace/test/build.xml:99: sonar:sonar doesn't support the "workDir" attribute
Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
Hence i deleted the working directory path in build.xml then i get this error
sonar:
[sonar:sonar] Apache Ant(TM) version 1.9.1 compiled on May 15 2013
[sonar:sonar] Sonar Ant Task version: 2.0
[sonar:sonar] Loaded from: file:/cip/opt/apache-ant-1.9.1/lib/sonar-ant-task-2.0.jar
[sonar:sonar] Sonar work directory: /cip/jenkins/workspace/test/.sonar
[sonar:sonar] Sonar server: http://localhost:9000/sonar
[sonar:sonar] *****************************************************************************************************************************************
[sonar:sonar] /!\ Sonar Ant Task running in compatibility mode: please refer to the documentation to udpate your scripts to comply with the standards.
[sonar:sonar] *****************************************************************************************************************************************
[sonar:sonar] Sonar version: 4.5.1
BUILD FAILED
/cip/jenkins/workspace/test/build.xml:99: java.lang.IllegalStateException: Fail to download libraries from server
at org.sonar.runner.Bootstrapper.downloadBatchFiles(Bootstrapper.java:166)
at org.sonar.runner.Bootstrapper.createClassLoader(Bootstrapper.java:89)
at org.sonar.runner.DeprecatedAntTaskExecutor.createClassLoader(DeprecatedAntTaskExecutor.java:123)
at org.sonar.runner.DeprecatedAntTaskExecutor.execute(DeprecatedAntTaskExecutor.java:65)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:86)
at org.sonar.ant.SonarTask.execute(SonarTask.java:75)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:9000/sonar/batch/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
at java.net.URLConnection.getContent(URLConnection.java:748)
at org.sonar.runner.Bootstrapper.remoteContent(Bootstrapper.java:125)
at org.sonar.runner.Bootstrapper.downloadBatchFiles(Bootstrapper.java:158)
... 22 more
Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
What could be the possible reason for such error?
Thank you for answering.
Yes, indeed its a sonar-ant-task version incompatibility
sonarqube1.0 version is not compatible with Sonarqube 4.5.1 .
After copying Sonarqube-ant-task-2.4 in apace-ant-1.8.4/lib
the job got executed
I'm using Ant 1.9.3 and Tomcat version 8.0. I'm using the Ant deploy target to deploy web apps in the Apache Tomcat using the manager credentials. The deploy target fails with the following exception:
java.lang.NoClassDefFoundError:
org/apache/tomcat/util/codec/binary/Base64
at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalina
Task.java:204)
at org.apache.catalina.ant.DeployTask.execute(DeployTask.java:196)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.util.codec.binary
.Base64
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 19 more
When I tried to find the class Base64 in the package org\apache\tomcat\util\codec\binary\ which is in tomcat-util.jar, and it is in the classpath which I've verified by an echo in Ant build file.
I'm not able to solve the issue.
Just in case someone runs into the same problem I was having:
I was following the tutorial on the Tomcat website and I ran into the same NoClassDefFoundError issue when I tried to run ant install.
The tutorial mentions that you have to copy $CATALINA_HOME/lib/catalina-ant.jar1 (which contains the implementation code for the Ant custom tasks) to the lib directory of your Ant installation.
It does not mention, however, that you need to do the same thing for tomcat-util.jar. As soon as I copied tomcat-util.jar to my Ant directory, things started working (source).
1$CATALINA_HOME is the directory of your Tomcat installation, e.g. /usr/share/tomcat8
Please make sure you have added the tomcat-util.jar in the classpath as below.
<path id="catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
<include name="tomcat-util.jar"/>
</fileset>
</path>
I have the following project directory structure:
MyProject/
src/main/java/
All of my Java sources
build/
build.xml
build.properties
ivy.xml
ivy-settings.xml
ivy-settings.properties
The build.xml looks like this:
<project name="MyProject" default="audit" basedir=".." xmlns:ivy="antlib:org.apache.ivy.ant">
<property file="build/build.properties"/>
<property environment="env"/>
<path id="ant.lib.path">
<fileset dir="${env.ANT_HOME}/lib" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ant.lib.path"/>
<target name="configIvy">
<echo message="Configuring Ivy."/>
<echo message="URL is: ${ivy.settings.home}"/>
<ivy:settings url="${ivy.settings.home}"/>
<!-- Clear/flush the Ivy cache. -->
<echo message="Cleaning the local Ivy cache for the current build."/>
<ivy:cleancache/>
</target>
</project>
When I run ant -buildfile /<path-to-my-project>/MyProject/build/build.xml configIvy, I get the following console output:
Buildfile: /<path-to-my-project>/MyProject/build/build.xml
configIvy:
[echo] Configuring Ivy.
[echo] URL is: file:////<path-to-my-project>/MyProject/build/ivy-settings.xml
[ivy:cleancache] :: Apache Ivy 2.3.0-rc1 - 20120416000235 :: http://ant.apache.org/ivy/ ::
BUILD FAILED
/<path-to-my-project>/MyProject/build/build.xml:85: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.ivy.util.url.URLHandlerRegistry.getHttp(URLHandlerRegistry.java:47)
at org.apache.ivy.ant.IvyAntSettings.configureURLHandler(IvyAntSettings.java:367)
at org.apache.ivy.ant.IvyAntSettings.createIvyEngine(IvyAntSettings.java:267)
at org.apache.ivy.ant.IvyAntSettings.getConfiguredIvyInstance(IvyAntSettings.java:237)
at org.apache.ivy.ant.IvyTask.getIvyInstance(IvyTask.java:92)
at org.apache.ivy.ant.IvyTask.prepareTask(IvyTask.java:256)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:276)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.NullPointerException
at org.apache.log4j.Category.isDebugEnabled(Category.java:129)
at org.apache.commons.logging.impl.Log4JLogger.isDebugEnabled(Log4JLogger.java:239)
at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:69)
... 25 more
My ivy-settings.xml file specifies a URL resolver of an Artifactory repo that is hosted on my local machine (http://localhost:8080/artifactory/myrepo). I'm wondering if Ivy uses HttpClient under the hood (as the stacktrace suggests), and for some reason, is choking because its an HTTP URL on the same machine? Maybe?!? And yes, I'm sure that the URL is correct and that Artifactory is running while I run the Ant build!
Can anyone spot what is going on here? Why would <ivy-cleancache> throw a NPE? I'm looking at its source code and can't seem to find where the NPE is coming from, or why. I can supply more details if needed. Thanks in advance!
I thought I gave a response to this, but I don't see it here...
Don't put extra jars for your projects into $ANT_HOME/lib. There are several reasons for this:
As you've found out, there can be jar clash as each set of optional tasks tries to setup the classpath they need. Yes, it's nice not having to set a classpath when you do a <taskdef>, but it's not that bad.
If you give your project to someone else, they'll have to install all of the optional jars too before they can do a build.
The better way is to create a ${basedir}/ant.lib directory, and then put each set of ant task jars in their own sub-directory. For example, you'd put Ivy jars in ${basedir}/ant.lib/ivy and you put Checkstyle jars in ${basedir}/ant.lib/checkstyle. Then, you define your taskdef with a classpath pointing to the directory like this:
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant">
<classpath>
<fileset dir="${basedir}/lib/ivy"/>
</classpath>
</taskdef>
This way, Ivy doesn't pick up the wrong jars. As a bonus, you can also give someone your project, and Ivy is already installed and running for them. No need for them to download Ivy and setup the jar in the right classpath.
By the way, $ANT_HOME/lib is already in the Ant classpath, so if you didn't specify a classpath, all the jars in $ANT_HOME/lib will be picked up automatically. You could have simply done this:
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant"/>
with no classpath required.
I am trying to run a Java class as part of the deployment of my project (I want to create some resources at deployment, which can then be read at runtime).
For the most part, I am using maven for the build cycle - in particular for dependency management.
This what I've got to; creating a path (run), and adding the dependencies from maven using the maven ant tasks, and then running a target that calls a java class (MyClass), which has been compiled to ...MyClass.class in the target\src directory, using a classpath of that directory and the run path specified above.
<path id="run" />
<artifact:dependencies pathid="run">
<artifact:pom file="pom.xml" id="my_project" />
</artifact:dependencies>
<target name="runMyClass">
<java classname="...MyClass" fork="yes" maxmemory="512M" append="true">
<classpath>
<pathelement location="target\classes"/>
<pathelement id="run" />
</classpath>
</java>
</target>
I know that the target\classes is correct - if I comment out the addition of the run path, it finds the class, but reports that some of the imports in the class are not available on the classpath.
However, when I run this, I get the following stack trace:
C:\somepath\my_project\build.xml:118: java.lang.NullPointerException
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:32)
Caused by: java.lang.NullPointerException
at org.apache.tools.ant.types.resources.FileResourceIterator.addFiles(FileResourceIterator.java:104)
at org.apache.tools.ant.types.resources.FileResourceIterator.<init>(FileResourceIterator.java:95)
at org.apache.tools.ant.types.Path$PathElement.iterator(Path.java:124)
at org.apache.tools.ant.types.resources.Union.getCollection(Union.java:123)
at org.apache.tools.ant.types.resources.Union.getCollection(Union.java:107)
at org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.cacheCollection(BaseResourceCollectionContainer.java:265)
at org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.iterator(BaseResourceCollectionContainer.java:142)
at org.apache.tools.ant.types.Path.iterator(Path.java:710)
at org.apache.tools.ant.types.resources.Union.getCollection(Union.java:123)
at org.apache.tools.ant.types.resources.Union.list(Union.java:86)
at org.apache.tools.ant.types.Path.list(Path.java:378)
at org.apache.tools.ant.types.Path.addExisting(Path.java:331)
at org.apache.tools.ant.types.Path.addExisting(Path.java:319)
at org.apache.tools.ant.types.Path.concatSpecialPath(Path.java:572)
at org.apache.tools.ant.types.Path.concatSystemClasspath(Path.java:532)
at org.apache.tools.ant.types.CommandlineJava.haveClasspath(CommandlineJava.java:647)
at org.apache.tools.ant.types.CommandlineJava.addCommandsToList(CommandlineJava.java:437)
at org.apache.tools.ant.types.CommandlineJava.getCommandline(CommandlineJava.java:405)
at org.apache.tools.ant.types.CommandlineJava.describeCommand(CommandlineJava.java:482)
at org.apache.tools.ant.taskdefs.Java.checkConfiguration(Java.java:176)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:107)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
... 16 more
To me, this looks like an exception is being thrown in the ant code in the process of adding the path set to the classpath, but I could be wrong.
Can anyone suggest (any of the following):
how I might go about debugging this?
an alternative approach to do what I'm trying to do (described
above)?
A little further playing gave me a workable solution...
Rather than refering to the maven dependencies as a path, I can refer to them using a fileset:
<fileset id="run" />
<artifact:dependencies filesetid="run">
<artifact:pom file="pom.xml" id="my_project" />
</artifact:dependencies>
<target name="runMyClass">
<java classname="...MyClass" fork="yes" maxmemory="512M" append="true">
<classpath>
<pathelement location="target\classes"/>
<fileset refid="run" />
</classpath>
</java>
</target>
I don't know what was going on with the other approach, whether it's user error or a bug, so if anyone has any suggestions, I would appreciate comments.