Maven: Failed to load class for data source: com.databricks.spark.csv - scala

I have a Maven project and I can't make it run:
Exception in thread "main" java.lang.ClassNotFoundException: Failed to load class for data source: com.databricks.spark.csv.
How to fix this in Maven?
PS: I know about this question, but I cannot use any additional options to spark-submit, except --class and --master.

Try maven-shade-plugin in you pom it will create one shade jar with your all dependencies or classes. For more detail go through this link

Related

Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer

i have a kafkaflink job which works in intellij, on packaging with sbt i get the below message
Caused by: java.lang.ClassNotFoundException:
org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer
Thanks for having a look at it
You most certainly have Kafka as provided dependency or you are not creating the fat-jar.
You need to use a plugin depending on the build tool You are using for sbt it can be sbt assembly, for maven it can be maven-shade-plugin. And then You need to have flink-kafka-connector in compile scope.

Error occurred during initialization of boot layer java.lang.module.FindException executing Selenium tests using TestNG and Java 12 through Eclipse

ErrorOccuredDuringInitializationofbootlayer I keep getting this error when I run
my test:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for
C:\Users\Bonfire.eclipse\org.eclipse.platform_4.12.0_867647348_win32_win32_x86_64\plugins\com.beust.jcommander_1.72.0.jar
Caused by: java.lang.IllegalArgumentException:
com.beust.jcommander.1.72.0: Invalid module name: '1' is not a Java
identifier
How can I fix it?
Add TestNG Library to classpath in buildpath ( not to module path). It will work fine.
To avoid this error, do not add TestNG library in the project or src folder. Try adding it into the package. To do so , follow the below mentioned procedure.
Right click on the package, click Build Path->Configure Build Path, go to Libraries tab, select Classpath and click on Add Library to select TestNG.
This error message...
Error occurred during initialization of boot layer java.lang.module.FindException:
Unable to derive module descriptor for C:\Users\Bonfire.eclipse\org.eclipse.platform_4.12.0_867647348_win32_win32_x86_64\plugins\com.beust.jcommander_1.72.0.jar
Caused by: java.lang.IllegalArgumentException: com.beust.jcommander.1.72.0: Invalid module name: '1' is not a Java identifier
...implies that there was an issue with the java classpath.
As per the discussion Launch with java 11 fails: Error: Could not find or load main class with Caused by: java.lang.ClassNotFoundException: with there are some issues with some particular classpaths for java-11 and the launch fails if:
The classpath contains a folder with spaces
The classpath length is larger than 32767 characters.
Where as java-8 works fine.
Reference
Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11
Outro
Eclipse plugin: TestNG testcase does not run with Jdk11
Need to add 1.8 version library
Remove TestNG from build path library and add again
Recheck - the issue should be resolved.
I got same issue and I solved it. When creating the project, don't create module-info.java. When the project was already created with the module-info.java, deleting this file didn't help me.
I just created new project without module-info.java, and all works good now.
Best option to resolve this:
Find all file and folder starting with . e.g. — .metadata / .setting and delete them.
Add all the JARS.
Add testNG Libraries.
Execute it.
Done.

How can I compile a scala project in eclipse with dependencies?

I'm doing a scala-spark app that gets data from MySQL. If I run from eclipse it works. However, if I create the .jar and execute it with spark-submit does not work, and an error appears:
Exception in thread "main" java.sql.SQLException: No suitable driver
So I think there are not dependencies at the created jar. I think I'm not setting the right plugin to compile with dependencies at pom.xml. Do you know which one is the plugin to do it?
Thank you, regards!
u can use "--jars $(echo lib/*.jar | tr ' ' ',')" option in the spark-submit , and put all your dependencies jar in lib folder .

Why am I getting this NoClassDefFoundError from my code?

I have been trying to use a Jar file as a library in my code, and it compiles fine. However, at runtime, I keep getting the NoClassDefFoundError message. Why is this happening? I have included the Jar file in the compile path and the runtime path too.
Here is the error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.pdfbox.cos.COSDocument.(COSDocument.java:51)
at org.apache.pdfbox.pdmodel.PDDocument.(PDDocument.java:136)
at processing.PDFToJPG.main(PDFToJPG.java:58)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
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)
... 3 more
Here is my code:
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
public static void main(String[] args) {
try {
PDDocument doc = new PDDocument();
} catch (Exception e) {
e.printStackTrace();
}
}
I am using NetBeans IDE as well as Windows 10
This is my setting for compile classpath:
[
This is my setting for runtime classpath:
[
EDIT: Thank you for your help, it really worked. All i needed to do was to download the dependencies Jar file, not editing the classpath like what i have been trying to do
I think you need another jars besides the one you have already included. Try to add common-logging 1.4. Apparently, there is a dependency between pdfbox1.8.jar and this jar as stated on their site.
EDIT: There are more dependencies fontbox and jempbox to take in account as well.
EDIT2: I made a zip with all dependencies needed you can download it here.
I agree with Aurelien's post: it looks like you are missing Apache Commons Logging - and other runtime dependencies.
You might want to consider creating your project as a 'Maven' Project (And Netbeans supports Maven pretty well): and then adding 'pdfbox' as a 'dependency'; this should make life a lot easier for you - since Maven will fetch any other required dependencies.
You can get the 'Maven Coordinates' for the various PDFBox versions from here:
http://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox
If you want to build your final project into a single JAR containing all the deps; or to create a separate 'lib' directory of them: you will have to make some minor changes to the Maven project file ('pom.xml') to do this.
This Stackoverflow Post has an example of doing that.

Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

I've a gradle project which uses hibernate > 4 . If I run my war file in Apache tomcat, I don't get any error. But when I'm deploying it in Wildfly 8.2 , I get the following exception
Caused by: org.hibernate.InvalidMappingException: Error while parsing file: /G:/wildfly-8.2.0.Final/bin/content/mywar-1.0.war/WEB-INF/classes/com/mysite/
hbm/Role.hbm.xml
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1182) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:848) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.
3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.
jar:4.3.7.Final]
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
... 8 more
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:518) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:514) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:688) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:726) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1177) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
... 14 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot
be cast to org.dom4j.DocumentFactory
at org.dom4j.io.SAXReader.read(SAXReader.java:484) [dom4j-1.6.1.jar:1.6.1]
I just added a exclude in my Gradle file like
runtime.exclude group: "dom4j"
Now when I run gradle build, dom4j.jar is not created in the war file. Now I can run my deploy and run my project successfully on Wildfly 8.2 without any error. But the real problem starts here.
One of the feature in my project is that, it'll copy a file.xlsm to anotherfile.xlsm where I'm using jars like Apache Poi for those purposes. Here, Apache Poi is trying to access a method in dom4j.jar during file processing, it results in the following error
18:40:13,261 ERROR [io.undertow.request] (default task-29) UT005023: Exception handling request to /app/parentPath/myAction: org.springframework.web.util.NestedSe
rvletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1287) [spring-webmvc-4.1.4.RELEASE.jar:4.1.4
.RELEASE]
Any ideas how I can permanently use dom4j.jar inside my classpath? I've searched for many question and most of them suggested to remove dom4j from classpath. I do successfully run my program by removing it from classpath but it results in the above error during excel file processing. Wasted more than a day on this..!! IS it possible to include dom4j.jar in my classpath?
Update:
I've done a little trick in MANIFEST.MF file.
I've opened
mywar.war > META-INF > MANIFEST.MF
and added
Dependencies: org.dom4j export
at the end of the file and saved it. So if I deploy my war file, I'm successfully running it without any error.
Can someone explain where I've to add this kind of property in my src/ file so that it will be automatcially added to MANIFEST.MF after gradle build..
This exception on wildfly usually occurs when you include a hibernate lib in your war that's different from the wildfly one, since you are deploying to wildfly it already include hibernate so you can set you live as provided in gradle aka compileProvided and deploy without exporting the dependence.
If you still got the same error try declaring the hibernate dependency on manifest but keep the lib as provided it should work fine.
I had this same problem and i know how frustrating this one can be. I was able to resolve this problem. see my answer here. Hope this help