I have an ear file, inside ear file I have the war file. Its based on Spring 2.5.6 and jdk 1.6
now I want to publish few messages to kafka, included kafka-clients-1.0.0 in war/web-inf/lib
but its getting NoClassDefFoundError org/apache/kafka/clients/producer/KafkaProducer.
NoClassDefFoundError usually happens when your project has conflict dependencies, for example 3rd and 4th versions of Spring framework. Check your dependencies and their transitive ones.
It simply means the class which you are trying to run was not found in on your classpath.
Solution: you need to add the class or .jar file which contains this class into the java classpath.
Related
I have exported two jars of two apps I have in the same Kafka/Spark Streaming project.
The jar with the Kafka Producer works fine. The jar with the Spark Consumer returns this error:
NoClassDefFoundError: kafka/serializer/StringDecoder
They share the same dependencies folder, which I have obviously exported in order to make the jars work outside Eclipse.
In Eclipse they both work fine.
How can I fix this?
You need Kafka itself in the class path, not just spark-streaming-kafka. In Eclipse you do, because your build system retrieves all dependencies, and Eclipse integrates with it.
I looked into the jar of spark-streaming-kafka and it contains the .class file that is named in the error: org.apache.spark.streaming.kafka.KafkaUtils$.createStream(KafkaUtils.scala:55). So I can't understand why he misses this class.
Presumably you mean that contains org.apache.spark.streaming.kafka.KafkaUtils$, but when JVM tries to load it, it discovers that it needs other classes, including kafka.serializer.StringDecoder, which is not there.
I wanted to understand parent-last loading in an application JBoss application server. We have a legacy application deployed in JBoss 4.2.1 GA. For which we are trying the parent-last loading.
I am referring to the this link.
I wanted to learn a parent last loading. So had created simple maven jar package application with maven-jar-plugin and configuration -> addDefaultImplementationEntries = true. I have created 2 jar versions 1.0.0 and 1.0.1 from the same jar creation maven application. The jar has single class TestClass and a simple String return method that returns the version of the jar the class is loaded from.
what I wanted to experience the use of java2ClassLoadingCompliance. I have packaged the version 1.0.0 jar in the server/deploy/MyApplication/WEB-INF/lib (My web application is a simple servlet application that calls the method of the class thus printing the version number from which jar it was called from.) and version 1.0.1 jar in server/lib.
Note : Logically it does not make sense to use an older version of jar in application and overriding it with the newer version present in server lib, but just wanted to experience the class loading.
I have tried the following
Without any jboss-web.xml in the meta-inf folder.
I tried introduction jboss-we.xml in META-INF and doing the same with java2ClassLoadingCompliance = false.
With java2ClassLoadingCompliance = true.
All the time class from the application lib would get loaded by the application.
My jboss-web.xml looks like reference
<jboss-web>
<class-loading java2ClassLoadingCompliance="true">
<loader-repository>
com.example:archive=JBossClassLoadingTestServlet-0.0.1-SNAPSHOT.ear
<loader-repository-config>java2ParentDelegation=true</loader-repository-config>
</loader-repository>
</class-loading>
</jboss-web>
Can someone help me understanding parent-last configuration in JBoss? What is the mistake I am doing here that always class from application lib gets loaded?
I am afraid that your link is not so related to your experiment. It is more related about the EAR deployments, in which there exists multi-module deployments and need multiple versions of the lib to isolate.
In your case, you just override lib in one Jar.
The following is from Servlet Spec:
It is recommended also that the application class loader is implemented so
that classes and resources packaged within the WAR are loaded in preference to
classes and resources residing in container-wide library JARs.
So, JBoss follow the spec and it always loads application lib first.
I didn't find such old version doc, but it should similar as AS7:
In order of highest priority to lowest priority
System Dependencies - These are dependencies that are added to the module automatically by the container, including the Java EE APIs.
User Dependencies - These are dependencies that are added through JBoss-deployment-structure.xml or through the Dependencies: manifest entry.
Local Resource - Class files packaged up inside the deployment itself, e.g. class files from WEB-INF/classes or WEB-INF/lib of a war.
Inter-deployment dependencies - These are dependencies on other deployments in an ear deployment. This can include classes in an ear's lib directory, or classes defined in other EJB jars.
Related:
a similar jetty classloading problem
I'm trying to deploy WAR file into JBoss 7.
I placed the WAR file in the standalone/deployments folder.
while starting the server I’m getting ClassNotFoundError.
I believe Since the jars are not part of the WAR file and not placed in the WEB_INF/lib folder so I need to add them externally.
I read so many tutorials but I just can’t understand how it works.
So my question is how I simply add JAR files to the JBoss classpath.
If you want to add any jars that are not part of WebApp but are still needed to be loaded, one approach would trying to copy the jars at following location:
$JAVA_HOME/jre/lib/ext.
The JBOSS server should point to this java installation and this might resolve your issue.
This might be one way.
JBOSS 7 uses module based loading, hence most of the jars will be loaded if module is included in standalone.xml.
You will need to check in JBoss Release notes if third party modules can be loaded.
Ok I solved it by creating new module and by adding the module dependency in the MANIFEST of my jar.
My spring boot web app works when run it in eclipse but when I try to run as an executable jar it fails to register any of the beans.
The configuration is all annotated - there are no xml config files.
I used mvn clean compile and mvn package commands to generate the jar.
Has anyone had a similar problem or have any ideas?
Thanks
Executable jars can not include nested jars, so it is necessary to workaround that limitation. A common approach is to shade the jars (i.e. unpacking all jars, and then packing in to single jar).
Spring-boot takes a different approach that relies on a custom maven repackaging plugin and handling by the Spring Boot Loader module. It generally just works, but per the documentation:
The spring-boot-starter-parent POM includes configuration
to bind the repackage goal. If you are not using the parent POM you
will need to declare this configuration yourself. See the plugin
documentation for details.
More information:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application-executable-jar
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar
My guess is that you are are you either not using the spring-boot maven plugin, or are not using the spring-boot parent POM. If that's not the issue, then you will need to post more information.
I have now resolved the problem and the app is working as a standalone jar.
Turns out the project folder structure was wrong - such that most of the app was unreachable!
I have a Java class from which I generate a WSDL and other files using the Web service wizard. What's starting to happen now is when I try to generate a web service, somehow, in the lib folder, a commons-logging-1.0.4.jar file gets generated and after that I'm informed that I have two commons-logging jar in the classpath (which makes sense since I really have another in the EAR project). What can I try?
TLDR: When I try to generate a webservice from a Java file, it also generates commons logging then tells me I have another commons logging in the classpath - the one it generates!
The problem wasn't with the commons-logging jar, it was with an unrelated jar on the classpath which contained Log.java file. Renaming the jar helped the issue. Bottom line - I should have used Ctrl+Shift+T to track everything that contains the Log class.