Jboss is not using jboss lib jar commons-lang3-3.0.jar - ant

I am using Ant to build my project and deploy it to JBoss. Ant is building using jboss-home/server/default/lib jars. But during deployment it gives error:
java.lang.Error: Unresolved compilation problems:
The import org.apache.commons.lang3 cannot be resolved
StringUtils cannot be resolved
I am using commons-lang3-3.1.jar for StringUtils class by following Ant entry:
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar">
<include name="{jboss.home}/server/default/lib/commons-lang3-3.1.jar" />

Well, for me it seems like compilation error, but still I can suggest a few things.
Try to include 'missing' library into your aplication (for example, place it into web-inf/lib if it is war packaging or use descriptor - application.xml or jboss-app.xml) and see what will happen.
Check if your jboss is actually using the lib: the fact, that jar is located inside jboss directory, does not mean that it will be actually loaded. I don't know what version of jboss you are using, but for jboss as7 it is possible to disable any jar from modules via module.xml or via specific server configuration file (like, standalone.xml).

Related

executable jar from groovy sources

I could not find a proper answer to the following question : while creating an executable jar from groovy compiled sources, I cannot simply include groovy-all-version.jar in a lib directory (as I would do in java) but I need to extract all the classes from the jar and package them with my own classes as otherwise I get an exception. This actually is the case with all libraries I may want to use.
Not clear ? Let's see an example.
toto.groovy belonging to package titi is compiled in a build directory which looks like this :
build
lib
groovy-all-1.8.4.jar
titi
toto.class
and a MANIFEST.MF that will be included in the jar contains the lines:
Main-Class: titi.toto
Class-Path: lib/groovy-all-1.8.4.jar
Executable jar creation is done with the following ant target in build.xml:
<jar destfile="${build.exe.dir}/${exe.name}"
basedir="${build.dir}"
manifest="${src.conf.dir}/MANIFEST.MF"
/>
Now if I try to execute the jar, I get
$ java -jar target/toto.jar
Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/Script
(I've checked that the groovy.lang.Script class exists.)
On the other hand, if I unjar groovy-all-version.jar in build by adding an unjar task before the jar, execution goes fine. OK, it works, but it slows down the compilation process and I'd like to understand...
Any feedback is highly appreciated.

Worklight ant task using apache commons - where is this loaded from?

I'm trying to diagnose a failure in my ant file when it runs a Worklight task. I have a small ant file containing a simple reference to a Worklight task. This works correctly.
<target name="rawBuildApplication" >
<app-builder
applicationFolder="${applicationSource}"
environments="mobilewebapp"
nativeProjectPrefix="xxx"
outputFolder="${outputFolder}"/>
</target>
However when I invoke this ant file from a build control ant file (actually from the RTC build system) I get a failure (below), showing worklight failing to find an apache Java class. I assume there's some simple environmental difference, perhaps a classpath. It might help to figure it out if I knew where Worklight loaded the apache commons from. Right now I can't see anything in my environment in the case that works that points any apache Jar.
myAntFile.xml:146: java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.deleteQuietly(Ljava/io/File;)Z
at com.worklight.builder.util.BuilderUtils.<clinit>(BuilderUtils.java:672)
at com.worklight.builder.config.UserBuildConfiguration$Builder.<init>(UserBuildConfiguration.java:203)
at com.worklight.ant.builders.ApplicationBuilderTask.createBuildConfiguration(ApplicationBuilderTask.java:149)
at com.worklight.ant.builders.ApplicationBuilderTask.execute(ApplicationBuilderTask.java:80)
Edited: the cause is the use of -lib to add the RTC toolkit directory, exactly why this clashes and how to work around yet to be determined
Usually means you have version of the commons jar in your classpath, and its overriding the one packaged in the worklight-ant.jar. the apache commons files are inside the worklight-ant.jar file
Additional info from djna: I can confirm that when adding the Rational Team Concert (RTC) 3.0 toolkit to the ant classpath, either explicitly with -lib, or when selecting that option in the RTC Build definition some conflicting commons jars are added to the classpath. Worklight packages the classes it needs in its jar, but the -lib folder seems to take precedence.
My workaround is to replace the conflicting jars with later ones. I used these jars
commons-io-2.4.jar
commons-codec-1.8.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
I guess the other alternative is to upgrade to a newer RTC, but in our environment that's not currently possible.

how to override specific jre jars with third party jars in ant build

I am using Ant 1.7.1 to build our application in eclipse. My application is going to be deployed on WAS 6.1. As I am using sun.security.* package classes and sub-packages in my code (I know it is not recommended to use this package, but have no other option).
When I deployed the ear in WAS, I got a ClassDefNotFoundError for sun.security.x509.AlgorithmId class. I found that this class is not present in the desired package in IBM Jre ( this is the kind of reason why it is not recommended to use sun. packages).
I had to put IBM jars in my development classpath and made eclipse use these jars instead of my local JRE jars by putting the IBM jars ahead of the JRE jars in the eclipse - order and export. This is working fine.
Now, my question is, how to do the same ordering of the jars in ANT. I know how to specify the order of jars in ANT classpath. But how do I put the IBM jars ahead of JRE jars in ANT?
I tried setting the IBM jars in boot classpath. But doing that, ANT is not able to find java.lang because, the java classpath is out of boot classpath now.
<javac source="1.5"
target="1.5"
bootclasspathref="project.class.path"
destdir = "${build.classes.dir}"
srcdir = "${work.dir}/src"
debug="true"
encoding="UTF-8"
>
<classpath path="${java.library.path}"/>
</javac>
Please advise how to get this done.
Any help will be much appreciated. Thanks
I got a solution for this. I made the following change to 'javac' task:
<javac source="1.5"
target="1.5"
destdir = "${build.classes.dir}"
srcdir = "${work.dir}/src"
debug="true"
encoding="UTF-8"
>
**<compilerarg value="-Xbootclasspath/p:${toString:project.class.path}"/>**
</javac>
Ant it worked!!

#Grab annotation fails under Ant

I'm using a #Grab annotation to grab the definition of an Html parser I can give to the XMLSlurper (I think it's the tagsoup parser) and all is good when I run my script from the cmd line. If I invoke the same script from Ant I get an Ivy NoClassDefFound error. I think it may berelated to having Ivy in Antlib. Is there another way to parse Html without customizing the slurper via #Grab?
This:
#Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2' )
doc = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser()).parse(confluenceWebPageInputStream)
Works just fine from the command line but when I run it from an Ant build target:
<target name="update-wiki-chart">
<echo message="Will update chart for version ${version}"/>
<java dir="${basedir}" classname="groovy.lang.GroovyShell">
<arg value="ParseWikiPage.groovy"/>
<classpath refid="groovylib"/>
</java>
</target>
where groovyLib is a path ref pointing to the Groovy-1.8.6 jar downloaded from our internal Nexus repo, I get the NoClassDefFound error. I'm thinking this is probably due to having Ivy installed in Antlib causing the class loader to find it in two places. I just thought of something while writing this post. I can probably run java in forked mode or do something to cause it to not see/share Ant's classpath.It's been a few years since I've wrestled w/ Ant and class loader issues. My project is a little delinquent due to the bug and I'm looking for a quick/easy fix.
I just tried running my groovy on the cmd line via the "java" cmd and loading groovy-all jar in the class path and I realized that I get the NoClassDefFound error there as well. It has nothing to do with collisions with Ivy under Antlib. Rather, I am missing Ivy altogether. I had assumed it was included in Groovy-all.jar. I just need a clever way of passing Ivy from AntLib into my java task to get this all up and running.
Sounds like you're missing one or more jars from the classpath. I'd suggest digging around the classpathref you've labelled "groovylib".
A less error prone way to launch groovy from within ANT using the groovy ANT task.
Here's a similar example to your use-case:
Parse HTML using with an Ant Script
My example uses ivy directly to manage all build dependencies. The Grab annotations are still supported but obviously these would only manage the dependencies of the groovy script.

Include java libraries into own library

I created a little framework for myself which I want to use in multiple projects. I also want the distributed jar-file to include all external libraries so that my projects just need to include my library to access all external libraries.
I need this to simplify updating the external libraries.
So I placed this in my build.xml which adds all libraries from dist/lib into my own jar-file.
<target name="-post-jar">
<!-- Include all java libraries -->
<fileset dir="dist/lib" id="extern.libs">
<include name="*.jar" />
</fileset>
<!-- Add the libraries from the fileset to the project.jar -->
<jar jarfile="${dist.jar}" update="true">
<zipgroupfileset refid="extern.libs"/>
</jar>
</target>
But when I try to use external libraries like "org.zkoss.zk.ui.Component" I get the error that this library could not be found.
Is there a better way to include the external libraries into my own library so that my project can use them?
You can publish a Maven artifact, which users of your framework can then use without having to include the dependencies yourself--your pom is enough.
If you want to create an "all-in-one" artifact, consider something like OneJar or jarjar or Maven's Shade plugin to create a jar that has no external dependencies.
The standard classloader can't find class files inside a jar that is itself inside a jar. You must add every jar to the classpath, and not nest jars.
BTW, it would probably be a bad idea to allow nesting jars: you would end up with 6 or seven versions of commons-lang or log4j into every project, because many libraries depend on them.
You can use One-jar or Fat Jar.
If you use maven you can use maven-assembly plugin.
Depends on IDE...If you are using Eclipse then it is very easy...go to Properties->Build Path and then add library...

Resources