Deploying web app using Ant results in NoClassDefFoundError - java

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>

Related

ANT to Remote Tomcat Deployment gets 500

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.

Custom ant task exposed thru antlib.xml

I have a jar with an ant task in it. My com/mebigfatguy/stringliterals/antlib.xml is
<antlib xmlns:stringliterals="ant:com.mebigfatguy.stringliterals">
<taskdef name="stringliterals" classname="com.mebigfatguy.stringliterals.StringLiteralsTask"/>
</antlib>
running jar tf stringliterals.jar i get
META-INF/
META-INF/MANIFEST.MF
com/
com/mebigfatguy/
com/mebigfatguy/stringliterals/
com/mebigfatguy/stringliterals/antlib.xml
com/mebigfatguy/stringliterals/SLClassVisitor.class
com/mebigfatguy/stringliterals/StringLiteralsTask.class
com/mebigfatguy/stringliterals/SLMethodVisitor.class
com/mebigfatguy/stringliterals/Literal.class
META-INF/maven/
META-INF/maven/com.mebigfatguy.stringliterals/
META-INF/maven/com.mebigfatguy.stringliterals/stringliterals/
META-INF/maven/com.mebigfatguy.stringliterals/stringliterals/pom.xml
META-INF/maven/com.mebigfatguy.stringliterals/stringliterals/pom.properties
com/mebigfatguy/org/
com/mebigfatguy/org/objectweb/
com/mebigfatguy/org/objectweb/asm/
com/mebigfatguy/org/objectweb/asm/AnnotationVisitor.class
com/mebigfatguy/org/objectweb/asm/AnnotationWriter.class
com/mebigfatguy/org/objectweb/asm/Attribute.class
com/mebigfatguy/org/objectweb/asm/ByteVector.class
com/mebigfatguy/org/objectweb/asm/ClassReader.class
com/mebigfatguy/org/objectweb/asm/ClassVisitor.class
com/mebigfatguy/org/objectweb/asm/ClassWriter.class
com/mebigfatguy/org/objectweb/asm/Context.class
com/mebigfatguy/org/objectweb/asm/Edge.class
com/mebigfatguy/org/objectweb/asm/FieldVisitor.class
com/mebigfatguy/org/objectweb/asm/FieldWriter.class
com/mebigfatguy/org/objectweb/asm/Frame.class
com/mebigfatguy/org/objectweb/asm/Handle.class
com/mebigfatguy/org/objectweb/asm/Handler.class
com/mebigfatguy/org/objectweb/asm/Item.class
com/mebigfatguy/org/objectweb/asm/Label.class
com/mebigfatguy/org/objectweb/asm/MethodVisitor.class
com/mebigfatguy/org/objectweb/asm/MethodWriter.class
com/mebigfatguy/org/objectweb/asm/Opcodes.class
com/mebigfatguy/org/objectweb/asm/Type.class
com/mebigfatguy/org/objectweb/asm/TypePath.class
com/mebigfatguy/org/objectweb/asm/TypeReference.class
com/mebigfatguy/org/objectweb/asm/signature/
com/mebigfatguy/org/objectweb/asm/signature/SignatureReader.class
com/mebigfatguy/org/objectweb/asm/signature/SignatureVisitor.class
com/mebigfatguy/org/objectweb/asm/signature/SignatureWriter.class
as you can see the task class is there
I put the jar in ~/.ant/lib, and When i try to run a task that references it like this:
<target name="literals" xmlns:stringliterals="antlib:com.mebigfatguy.stringliterals" description="generate report of string literals used in code">
<stringliterals:stringliterals>
<classpath refid="fb-contrib.classpath"/>
</stringliterals:stringliterals>
</target>
I get
literals:
parsing buildfile jar:file:/home/dave/.ant/lib/stringliterals-0.2.0.jar!/com/mebigfatguy/stringliterals/antlib.xml with URI = jar:file:/home/dave/.ant/lib/stringliterals-0.2.0.jar!/com/mebigfatguy/stringliterals/antlib.xml from a zip file
Finding class com.mebigfatguy.stringliterals.StringLiteralsTask
BUILD FAILED
/home/dave/dev/fb-contrib/build.xml:245: The following error occurred while executing this line:
jar:file:/home/dave/.ant/lib/stringliterals-0.2.0.jar!/com/mebigfatguy/stringliterals/antlib.xml:2: taskdef class com.mebigfatguy.stringliterals.StringLiteralsTask cannot be found
using the classloader AntClassLoader[]
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:607)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:237)
at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:177)
at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:428)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:277)
at org.apache.tools.ant.ComponentHelper.checkNamespace(ComponentHelper.java:874)
at org.apache.tools.ant.ComponentHelper.getDefinition(ComponentHelper.java:307)
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:284)
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:263)
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:429)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
at org.apache.tools.ant.Task.perform(Task.java:347)
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.lang.ClassNotFoundException: com.mebigfatguy.stringliterals.StringLiteralsTask
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1366)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1315)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:579)
... 21 more
I've done this several times before with no issues, this time however i don't see where i've gone wrong. Any way to debug this classloader issue?
GitHub project here https://github.com/mebigfatguy/stringliterals
The problem turned out to be a badly formatted manifest file. sorry!

HtmlUnitDriver is throwing java.lang.ExceptionInInitializerError

I am writing an ant task which uses below code :
public class Klazz extends Task{
public void execute() throws BuildException{
HtmlUnitDriver driver = new HtmlUnitDriver();
driver.get("file:///C:/sample/alltests-fails.html");
}
In eclipse the project named is "test-project" and used "libs" folder which contains the jars (ant.jar, selenium-server-standalone-2.44.0.jar) to be added in the classpath . If I run the code in Eclipse its working fine but while running as an ant task it throws java.lang.ExceptionInInitializerError . Below is the build.xml snippet to create the jar(named custom-task.jar) file which needs to be put in the %ant_home%\lib folder.
<target name="jar" depends="compile" >
<mkdir dir="build/jar" />
<jar destfile="${env.ANT_HOME}/lib/custom-task.jar">
<fileset dir="build/classes" />
<restrict>
<name name="**/*.class" />
<archives>
<zips>
<fileset dir="${basedir}/libs/" includes="**/*.jar" />
</zips>
</archives>
</restrict>
</jar>
</target>
May be the external jars/classes not added properly in the class path while creating the jar through the "jar" task above, resulting some missing class files causing the ExceptionInInitializerError.
Advance thanks for any help on this .
below is the stack trace :
java.lang.ExceptionInInitializerError
at org.cyberneko.html.HTMLScanner.scanEntityRef(HTMLScanner.java:1415)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2
059)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499
)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452
)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.pars
e(HTMLParser.java:926)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:2
45)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.ja
va:191)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(Defau
ltPageCreator.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPa
geCreator.java:156)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient
.java:455)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:4
77)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:4
66)
at mypkg.Klazz.execute(Klazz.java:15)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at org.cyberneko.html.HTMLEntities.load0(HTMLEntities.java:101)
at org.cyberneko.html.HTMLEntities.<clinit>(HTMLEntities.java:53)
... 33 more
Total time: 2 seconds
Should there have been any class loading difficulties, I would assume a NoClassDefFoundError or a ClassNotFoundException would occur
The ExceptionInInitializerError is usually not what should draw attention, because it only says "Hey, programmer, an exception happened inside an initialization block"
More about initialization blocks here
Therefore, dealing with the NPE will fix the issue, but unfortunately I've no access to the code that could've caused this. Let me know and I shall edit the answer.
#Vlad Ilie thanks for having a look , its solved now.. the problem is with jar creation ant script .
The earlier ant task for the jar creation is not able to club all the jars in the class path and resulting... classnotfoundexception which in turn caused the ExceptionInInitializerError and NullPointerException .
Below is the fixed "jar" task which is successfully able to add all the jars in the class path .
<target name="jar" depends="compile">
<jar destfile="${env.ANT_HOME}/lib/custom-task.jar" basedir="build/classes" >
<zipgroupfileset dir="${basedir}/libs/" includes="*.jar"/>
</jar>
</target>
Above I used zipgroupfileset which is very handy .

Ivy CleanCache Task throwing NullPointException

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.

Weblogic Ant JWSC task to generate a webservice war file

I am running a jwsc ant task to generate a war file. It is working fine for me if I add the weblogic.jar to classpath before running the ant script (CLASSPATH=/opt/bea/weblogic91/server/lib/weblogic.jar export CLASSPATH)
But is is not working if I add this in my build.xml as follows:
<target name="GenerateWarFiles">
<path id="lib.jwsc.id">
<pathelement path="/opt/bea/weblogic91/server/lib/weblogic.jar"/>
</path>
<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" classpathref="lib.jwsc.id"/>
<jwsc srcdir="${src.java.dir}" destdir="${build.war.file.dir}" verbose="on" debug="on" classpathref="lib.jwsc.id">
<jws file="sep/com/bt/prf/jws/TypeImpl.java" compiledWsdl="${ivy.lib.dir}/WSDLC/Jwslib-8.0.jar" />
</jwsc>
</target>
I am getting the following error.
[AntUtil.deleteDir] Deleting directory /var/tmp/_927vxb
BUILD FAILED
/wls_domains/CIT/cruisecontrol-bin-2.8.3/util/Ivy/build.xml:231: Deployment descriptor: /var/tmp/_927vxb/web.xml does not exist.
at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:184)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
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:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: Deployment descriptor: /var/tmp/_927vxb/web.xml does not exist.
at org.apache.tools.ant.taskdefs.War.setWebxml(War.java:95)
at weblogic.wsee.tools.anttasks.JwscTask.jar(JwscTask.java:397)
at weblogic.wsee.tools.anttasks.JwscTask.pkg(JwscTask.java:331)
at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:166)
... 17 more
--- Nested Exception ---
Deployment descriptor: /var/tmp/_927vxb/web.xml does not exist.
at org.apache.tools.ant.taskdefs.War.setWebxml(War.java:95)
at weblogic.wsee.tools.anttasks.JwscTask.jar(JwscTask.java:397)
at weblogic.wsee.tools.anttasks.JwscTask.pkg(JwscTask.java:331)
at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:166)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
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:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 1 minute 3 seconds
I am running weblogic91 in Solaris.
I'm betting that in your deployment target (Which isn't posted here) is trying to 'clean' up the deployment directory, and is failing when it can't find the file called /var/tmp/_927vxb/web.xml
3 suggestions:
Run touch /var/tmp/_927vxb/web.xml from the command line and try to run the build/deployment again. This will create an empty file that will at least let you get past the file not found on delete error. This is not a long term solution, but rather an attempt to expose the real issue.
Look at line 231 in your /wls_domains/CIT/cruisecontrol-bin-2.8.3/util/Ivy/build.xml file. Perhaps there is a delete ant task that is failing on error. If this is the case, add `failonerror="false" to the ant task that is causing the issue.
Post more of your build file here. Being able to align the line numbers in the file with the error will help in decoding the issue.

Categories

Resources