I have the following contents in src/main/clojure/za/co/pb/maven_test/test.clj file:
(ns za.co.pb.maven-test.test
(:gen-class))
(defn -main []
(println "Hello world!"))
I also have a POM that has the necesary dependencies on clojure-maven-plugin with the compile execution.
If I execute a mvn package command, I get a target/maven-test-1.0-SNAPSHOT.jar file and if I look in the classes folder I have these files in the folder target/classes/za/co/pb/maven_test:
test.class
test.clj
test__init.class
test$loading__4410__auto__.class
test$_main.class
This, as far as I know, is appropriate.
However, when I run this command:
java -cp target\app-1.0-SNAPSHOT.jar za.co.pb.maven_test.test
I get this:
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/IFn
Caused by: java.lang.ClassNotFoundException: clojure.lang.IFn
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: za.co.pb.maven_test.test. Program will exit.
You don't have the clojure jars in the classpath. You can either embed them as per Stuart's response, or if you don't like having all the dependencies embedded in a single jar, you can use the dependency plugin and the jar plugin to get this working nicely.
See: http://groups.google.com/group/enclojure/msg/87159854fcb0e708 for a summary (note, there's a typo in the linked post, the package should be called "foo").
You need to generate a JAR file file that includes all the dependencies of your project. The Maven Assembly Plugin does this for you, using the built-in jar-with-dependencies descriptor.
If you are using leiningen, after generating the jar with lein uberjar, do not use java -jar target/your-name.jar, but use java -jar target/your-name-standalone.jar.
Same thing for boot.
Are all dependencies available ? I'm not familiar with the clojure.lang.IFn class. Is it from an external library? If it is did you marked the dependency with the provided scope?
Related
When The Program is Ran in the Local PC, it is working fine, but if it is running in the docker throws the following error:
Exception in thread "Thread-16" java.lang.NoClassDefFoundError: org/apache/kafka/common/serialization/Serializer
at org.eclipse.kura.example.configurable.ConfigurableExample$1.run(ConfigurableExample.java:52)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.serialization.Serializer cannot be found by org.eclipse.kura.example.configurable_1.0.0.202201251713
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
But this is working fine in the LocalMachine.
What is the issue ?
This may be debugged in following ways:
Ensure that you have all the required dependencies inside your docker container. You may want to check your docker base image first.
Check if you have set the classpath appropriately to include that jar file (kafka-clients).
Validate your entrypoint/cmd which you use to start the service to check if it has the appropriate classpath.
Check your classloader and see why it is not able to load that class.
If your executable is a fat jar file, check if that jar file contains the kafka-clients library where that class is present.
Java agent is throwing this error when running with a java 15 app, if anybody can shed a light on why this might be coming, it will be very helpful.
java.lang.NoClassDefFoundError: java/sql/PreparedStatement
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3325)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2466)
.
.
.
.
.
Caused by: java.lang.ClassNotFoundException: java.sql.PreparedStatement
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 19 more
Class not found Exception happens when JVM Doesn't find the class files on the classpath. Either the auto deployment feature(auto-deployment="true") is erroneous or you don't have class file(sql jar) on the classpath. If you are using Maven, Just check if sql jar(prepared statement class file and sql jar file) is on the classpath. If class file not on classpath, Just add the class file manually on classpath. It should resolve the error.
It means java.sql.PreparedStatement is available at compile time but not available at Runtime.
To solve the issue add the sql jar to classpath, if you are using maven add dependency in pom.xml.
I have springboot application which is connecting to client shared dynamic library using jni.
There is one **callback method **which is registered to dll using ine register function.
This method is invoked on some events from dll.
When executed as java application from intellij, this works fine but when executed **as jar **and when this callback method is invoked its throwing **NoClassDefFoundError ** as below
java.lang.NoClassDefFoundError: com/test/Sample
Caused by: java.lang.ClassNotFoundException: com.test.Sample
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java: 424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
By default springboot puts all classes inside BOOT-INF folder.
When I manually modified jar and added this class outside BOOT-INF i.e at rootLevel it worked.
Like below:
BOOT-INF
com
META-INF
org
In above snippet com is directory inside which Sample class was present under subpackage test.
springboot version used: 2.3.6.RELEASE
Using springboot-maven-plugin to create executable jar
Can you please help me with following error I'm facing in WAS9 environment:
In order to resolve the import
org.apache.cxf.binding.soap.SoapHeader
I added the following dependencies in my pom.xml:
cxf-api-2.7.7
cxf-rt-bindings-soap-2.7.7
But when I'm trying to run my application, I'm getting the following error.
Default Executor-thread-7] ([ ]) Controllerclass - org.apache.cxf.bus.extension.ExtensionException
at org.apache.cxf.bus.extension.Extension.load(Extension.java:222)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.loadAndRegister(ExtensionManagerImpl.java:199)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.initialize(ExtensionManagerImpl.java:118)
at org.apache.cxf.bus.extension.ExtensionManagerBus.doInitializeInternal(ExtensionManagerBus.java:147)
at org.apache.cxf.bus.CXFBusImpl.initialize(CXFBusImpl.java:191)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createBus(LibertyApplicationBusFactory.java:119)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createClientScopedBus(LibertyApplicationBusFactory.java:86)
at com.ibm.ws.jaxws.metadata.JaxWsClientMetaData.<init>(JaxWsClientMetaData.java:28)
at com.ibm.ws.jaxws.metadata.JaxWsModuleMetaData.getClientMetaData(JaxWsModuleMetaData.java:123)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:84)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:123)
at com.ibm.ws.jaxws.client.LibertyProviderImpl.createServiceDelegate(LibertyProviderImpl.java:56)
at javax.xml.ws.Service.<init>(Service.java:57)
Caused by: java.lang.InstantiationException:org.apache.cxf.bus.osgi.OSGIBusListener
at java.lang.Class.newInstance(Class.java:427)
at org.apache.cxf.bus.extension.Extension.load(Extension.java:218)
Caused by: java.lang.NoSuchMethodException:org.apache.cxf.bus.osgi.OSGIBusListener.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
The server where your WAS9 has been deployed has different version of the above jar file. You need to have same version of jar files both in your eclipse where you have developed your codes and the server where you are deploying the war or ear.
mavan dependency file pom.xml is used during your project compilation. It might add the jar in your binary under lib folder as well. But WAS9 might considering the one which is in server's CLASSPATH. Hence check your class path and replace that jar with the one which you have mentioned in your pom.xml file. Hope that will fix your issue.
We can eliminate this exception by adding webProfile-7.0 in our server.xml, but how ever this is not working with javaee-7.0 not sure, if one knows about how to handle this in javaee-7.0 please share your approach.
I'm learning how to write a map / reduce job in hadoop with mongodb data as input. So I followed this example, but I got following error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/hadoop/util/MongoConfigUtil
at WordCount.main(WordCount.java:58)
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.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: com.mongodb.hadoop.util.MongoConfigUtil
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I've been searching for hours without any result. Any one can help me please.
it means mongo-hadoop-core.jar is available at compile time but not at run time.
Try running your application with dependency jars added in classpath
Example : java -cp mongo-hadoop-core.jar<++other dependencies> MainClass
EDIT 1
If you're running using hadoop shell
check the classpath by executing hadoop classpath it will print the dir/jars in the classpath.
If the dependent jars are not in the classpath add them in the classpath using export command then execute hadoop jar yourjar.jar mainClass
EDIT 2
make use of libjars option
hadoop jar myjar.jar mainClass -libjars ${LIBJARS}
I can see this link examples folder structure is maven. I CANT see pom.xml in that link.
We can set maven scope from provided to runtime
You need to write assembly.xml (to package your application lib and related dependencies in tar file) and need to refer it from pom.xml to package mongo-hadoop-core.jar along with other dependencies which are NOT installed in cluster.
export HADOOP_CLASSPATH=`hadoop classpath`:`hbase classpath`
hadoop jar .... -cp $HADOOP_CLASSPATH MainClass
If you unzip the tar file mentioned above and you can refer the classpath for example :
hadoop jar .... ../lib/* main classs
where lib folder contails all your dependencies like your mongodb also.
If mongo db and related components are installed in the cluster we can mention the classpath like below example.
Also see this answer how they have used libjars