java.lang.NoClassDefFoundError: org/apache/axis2/client/Stub - java

I've added a Web Service using Axis2 to my project and now I can't run my application.
This is the classpath I am using:
<property name="classpath" location="bin:EventReservationCore/bin:EventReservationCore/db:EventReservationCore/lib/*:EventReservationCore/lib/util_iso2.jar:EventReservationCore/lib/sqlitejdbc-v056.jar:AuthorizationRMI/lib/AuthorizationService.jar:EventReservationCore/lib/activemq-all-5.4.3.jar:/home/ander/axis2-1.6.1/webapp/axis2.war"/>
And this is the target that runs until I add the Axis2 Web Service.
<target name="run.besocial">
<java classname="eventReservationServer.ReservationEventServer" classpath="${classpath}" fork="true">
<jvmarg value="-Djava.rmi.server.codebase=file:EventReservationCore/bin/ file:EventReservationCore/lib/util_iso2.jar"/>
<jvmarg value="-Djava.security.policy=EventReservationCore/java.policy" />
</java>
</target>
As a result I get this error:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis2/client/Stub
[java] at java.lang.ClassLoader.defineClass1(Native Method)
[java] at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
[java] at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
[java] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
[java] at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
[java] at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[java] at eventReservationServer.eventServerGateway.WSEventServerGateway.getEvents(WSEventServerGateway.java:19)
[java] at eventReservationServer.ReservationEventServer.<init>(ReservationEventServer.java:101)
[java] at eventReservationServer.ReservationEventServer.main(ReservationEventServer.java:130)
[java] Caused by: java.lang.ClassNotFoundException: org.apache.axis2.client.Stub
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[java] ... 15 more

If you are using tomcat, copy all the jar files located under axis2/lib folder to the tomcat/lib folder and also add them to the classpath like this D:\axis2-1.6.2\lib*

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis2/client/Stub
Above error can be removed by adding axis2-kernel-1.6.2 to the class path, but you might start getting other errors after you have generated the stubs with wsdl2java.bat.
So you better add all the axis2-jars to classpath while compiling the client.
Hope this helps

None of the answers helped me. Here is then what I did.
I used eclipse to generate Runnable Jar(right click->Export->Runnable Jar) with all the libraries added as package.
It gave me a JAR that I could run from command line.
Then I did diff between Jar from eclipse and Jar that my build created. I was able to find the missing dependencies that my build was not putting in Jar.

If you faced the same issue for JBoss class loader, follow the tips on here and here.
The most important part is to define a new module in JBoss module configurations, and also locate the module in you MANIFEST.MF file.
Maven will help you to do the later part. Following is a sample configuration to add axis module to your Manifest file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<archive>
<manifestEntries> <!--Manually added JBoss Modules (that are not found by JBoss class loader) must be loaded here-->
<Dependencies>axis.axis</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
Depending to your packaging type, you would use other maven plugins like maven-jar-plugin or maven-war-plugin.
The dependency package name must match the name that you have specified to your module name in JBoss modules. The above axis module is defined in JBoss models as explained in the links above.
<module xmlns="urn:jboss:module:1.1" name="axis.axis">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<!-- ... -->
</module>

Related

Incorrect classpath causing java.lang.NoClassDefFoundError

When I run my java application from the command line I get the following exception:
java -jar target/my-app.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/my_company/utilities/http_server/HttpServer
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.my_company.utilities.http_server.HttpServer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Looking into this I have discovered the following:
My local repo contains:
~/.m2/repository/com/my_company/utilities/http_server/0.0.1-SNAPSHOT/utilities-0.0.1-20151208.162219-2.jar
MANIFEST.MF contains the following entry in the classpath:
Class-Path: lib/utilities-0.0.1-20151208.162219-2.jar
and the target directory contains a lib subfolder with the following file:
utilities-0.0.1-SNAPSHOT.jar
My POM file contains the following entry:
<dependency>
<groupId>com.my_company.utilities</groupId>
<artifactId>utilities</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I can see that the exception is caused by the wrong entry in the classpath. But I don't know why that is wrong - i.e. why are the names different. Can someone help?
The exception does not occur if I run the application from within Eclipse.
Try disabling the <useUniqueVersions> configuration element:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
From Handling Snapshot Versions

Axiom throwing error for Axis2 generated WSDL

I have auto generated classes from a WSDL file using Axis2 wsdl2java script. After adding the generated Java files to a Maven project the dependencies were only axis2-adb and axis2-kernel. However during runtime it is throwing the following:
Caused by: java.lang.ClassNotFoundException: org.apache.axiom.util.UIDGenerator
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
and
Caused by: java.lang.NoClassDefFoundError: org/apache/axiom/util/UIDGenerator
at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:90)
at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:95)
at org.apache.axis2.description.TwoChannelAxisOperation.<init>(TwoChannelAxisOperation.java:52)
at org.apache.axis2.description.OutInAxisOperation.<init>(OutInAxisOperation.java:65)
at org.apache.axis2.description.RobustOutOnlyAxisOperation.<init>(RobustOutOnlyAxisOperation.java:47)
at org.apache.axis2.client.Stub.addAnonymousOperations(Stub.java:233)
at com.tobeprecise.sms.webservices.HttpReceiverStub.populateAxisService(HttpReceiverStub.java:42)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:184)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:173)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:222)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:214)
at in.capillary.nsadmin.gateway.tobeprecisebulk.TobepreciseBulkGatewayChannel.sendMessages(TobepreciseBulkGatewayChannel.java:122)
at in.capillary.nsadmin.gateway.BufferedGatewayChannelProcessor.process(BufferedGatewayChannelProcessor.java:150)
at in.capillary.nsadmin.gateway.BaseGateway.process(BaseGateway.java:207)
at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
... 18 more
While looking at the dependencies I have found the axiom-api-1.2.11 as a dependency and it very well contains the UIDGenerator class. Is this due to version mismatch?
Found a similar issue ClassNotFoundException axiom-api-1.2.7.jar but I coudn't make much sense out of it(my manifest file: http://pastebin.com/n4jKWPck). Any help?

Oozie Java Action : Passing Hbase classpath

I'm running a test hbase java program via oozie java action. The following error is encountered :
Failing Oozie Launcher, Main class [HbaseTest], main() threw exception, org/apache/hadoop/hbase/HBaseConfiguration
java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
at HbaseTest.main(HbaseTest.java:28)
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.oozie.action.hadoop.LauncherMapper.map(LauncherMapper.java:495)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:50)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:417)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:332)
at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1438)
at org.apache.hadoop.mapred.Child.main(Child.java:262)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 14 more
The program runs correctly from command line :
java -cp `hbase classpath` HbaseTest
Is there a way I can pass output of 'hbase classpath' to the oozie java action.
I dont want to copy hbase jars to workflow's lib directory as that will be a maintenance overhead.
Following is the java action from workflow.xml :
<java>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<main-class>HbaseTest</main-class>
<java-opts></java-opts>
<arg>HELLO</arg>
</java>
Since Oozie 2.3 you can use Share Libraries:
Oozie supports job and system share libraries for workflow jobs.
Share libraries can simplify the deployment and management of common components across workflow applications.
For example, if a workflow job uses a share library with the Streaming, Pig & Har JARs files it does not have to bundled those JARs files in the workflow application lib/ path.
If workflow job uses a share library, Oozie will include all the JAR/SO files in the library in the classpath/libpath for all its actions.
A workflow job can specify a share library path using the job property oozie.libpath .
A workflow job can use the system share library by setting the job property oozie.use.system.libpath to true .
http://oozie.apache.org/docs/3.2.0-incubating/WorkflowFunctionalSpec.html#a17_HDFS_Share_Libraries_for_Workflow_Applications_since_Oozie_2.3
How to install:
http://oozie.apache.org/docs/4.0.0/DG_QuickStart.html#OozieShareLib

Deploying web app using Ant results in NoClassDefFoundError

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>

executing jar file: Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext

I have created a maven project. After I type: mvn clean package everything works fine and I see my jar file inside target. But if I click the file I get the follwing error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/c
ontext/ApplicationContext
Caused by: java.lang.ClassNotFoundException: org.springframework.context.Applica
tionContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: comt.test.Test. Program will exit
I can run the project under Eclipse and works ok, but the jar file doesnt work.
This is the content of Manifest:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.6.0_23
Main-Class: com.stlpo.App
Class-Path: commons-httpclient-3.1.jar commons-codec-1.2.jar h2-1.2.138.jar
commons-lang-2.5.jar spring-core-3.0.3.RELEASE.jar spring-asm-3.0.3.RELEASE.jar co
mmons-logging-1.1.1.jar spring-context-3.0.3.RELEASE.jar spring-beans
-3.0.3.RELEASE.jar spring-expression-3.0.3.RELEASE.jar spring-orm-3.0
.3.RELEASE.jar spring-tx-3.0.3.RELEASE.jar spring-aop-3.0.3.RELEASE.j
ar aopalliance-1.0.jar spring-jdbc-3.0.3.RELEASE.jar spring-test-3.0.
3.RELEASE.jar cglib-nodep-2.2.jar logback-core-0.9.24.jar logback-cla
ssic-0.9.24.jar slf4j-api-1.6.0.jar hibernate-annotations-3.5.4-Final
.jar hibernate-core-3.5.4-Final.jar antlr-2.7.6.jar commons-collectio
ns-3.1.jar jta-1.1.jar hibernate-commons-annotations-3.2.0.Final.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar hibernate-entitymanager-3.5.4-F
inal.jar cglib-2.2.jar asm-3.1.jar javassist-3.9.0.GA.jar opencsv-2.1
.jar jfreechart-1.0.13.jar jcommon-1.0.16.jar commons-beanutils-1.8.3
.jar beansbinding-1.2.1.jar poi-3.6.jar log4j-1.2.13.jar
poi-ooxml-3.6.jar poi-ooxml-schemas-3.6.jar xmlbeans-2.3.0.jar stax-
api-1.0.1.jar geronimo-stax-api_1.0_spec-1.0.jar dom4j-1.6.1.jar xml-
apis-1.0.b2.jar commons-dbcp-1.4.jar commons-pool-1.5.4.jar TableLayo
ut-20050920.jar
Thanks in advance for your help.
When you build a JAR, it only has your classes in it. It doesn't contain all the other libraries that your project depends on. (Doing that is possible, but it's not common and mostly inadvisable.) To run a class in your JAR that depends on Spring, you have to be sure Spring is on the classpath, either by passing a classpath to the java executable (doesn't work if using the -jar argument) or by putting a "Class-Path" attribute in the JAR's manifest file. Of course, it's not just Spring. You'll have to include a classpath entry for every jar your project depends on.
see another post regarding the same problem
you need to create a classPath (the eclipse is dong it automatically for you, and this is why you have no problem ruining the project from the eclipse) for the dependencies (in your case the spring)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
<addClasspath>true</addClasspath>
<!-- use class path prefix if your dependencies are out side the jar)
<classpathPrefix>lib/</classpathPrefix> -->
</manifest>
<manifestEntries>
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>

Categories

Resources