i am new to maven, after running Maven with mvn clean package command.
it compiles the project into an executable jar.
i run the jar in the terminal and got this error:
$ java -jar create_pass_criteria-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/mprv/automation/core/exceptions/AutomationException
at Create_pass_criteria.Main.main(Main.java:23)
Caused by: java.lang.ClassNotFoundException: com.mprv.automation.core.exceptions.AutomationException
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)
... 1 more
i have a lot of jars that i use in my code by importing them.
how can i make the jar also include those jars?
is this what this error means?
appreciate any help,
thank you
Try it
Just add all the required libraries to the classpath when using java -jar target/PriseDeNotes-0.0.1-SNAPSHOT.jar with the --classpath argument.
Related
I got this error when running a maven built jar file:
I build my jar file using maven on NetBean, I able to run without issue on my Netbean, but when I run the jar file java -jar SimpleTestMQ-1.0-SNAPSHOT.jar this error happens:
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/MQEnvironment
at com.stee.simpletestmq.SimpleTestApp.main(SimpleTestApp.java:16)
Caused by: java.lang.ClassNotFoundException: com.ibm.mq.MQEnvironment
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
I´m trying to crawl a dynamic Webpage with Serritor but there is a Problem:
This is my Code:
public class MyCrawler extends BaseCrawler {
public MyCrawler() {
String pathToDriver = ".//ChromeDriver//chromedriver.exe";
System.setProperty("webdriver.chrome.driver", pathToDriver);
config.setWebDriver(new ChromeDriver());
config.setFilterOffsiteRequests(true);
config.addSeedAsString("http://yourspecificsite.com");
config.setCrawlingStrategy(CrawlingStrategy.DEPTH_FIRST);
config.setDelayBetweenRequests(Duration.ofSeconds(1));
}
}
And this the return:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/htmlunit/HtmlUnitDriver
at com.github.peterbencze.serritor.internal.CrawlerConfiguration.<init>(CrawlerConfiguration.java:47)
at com.github.peterbencze.serritor.api.BaseCrawler.<init>(BaseCrawler.java:68)
at serritor_versuch2.MyCrawler.<init>(MyCrawler.java:21)
at serritor_versuch2.run.main(run.java:5)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.htmlunit.HtmlUnitDriver
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)
... 4 more
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/htmlunit/HtmlUnitDriver
Above exception clearly states that HtmlUnitDriver class is not found. If you are using maven, you should probably add maven dependency in your pom.xml file.
Not sure, which version are you using but here is the latest version.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
If you are using gradle or any other dependency management tool, look accordingly from: Maven Repository
If you are not using any dependency management tool, you should download the jar file and put it in your classpath.
I was able to create an executable using launch4j and it works fine on my machine. When I send it to someone to run on their windows machine they get the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: spark/TemplateEngine
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: spark.TemplateEngine
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)
... 7 more
Any thoughts?
This exception may also occur if your maven dependencies do not have <scope> set to compile time (default) and dependency jars are not available at compile time. For instance if maven dependencies have <scope>provided</scope> in your pom.xml compiler will assume that the JRE/environment will provide these dependency jars but when the sources are compiled and these dependencies are not found, this exception will be thrown.
For example - below may lead to this exception if spark-mllib_2.11 dependency is not found during compile time although they are added and there is no error during editing;
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.11</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
I had this problem because my version of java that was as default was 9, and somehow Spark didn't recognize it. So I changed to version 8 and it worked. To change in linux :
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
In your case you may want another version, so choose yours (to list the versions you have in your computer use the -l option).
Had to set relative paths in the class path so the executable could locate the jar files
I am able to compile my code and run it in my local (windows) machine using Eclipse. However, when I do it on my remote (ubuntu) machine, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
at com.tools.App.main(App.java:36)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
I have added the following entry in my pom.xml file:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
Can someone please help me understand what else I need to do to get this working? Thanks.
that means the jar is available at compile time but when you are running your application this jar isn't present in classpath and so the error
Try to look into the build path of your project and see if commons-io artifact is present there in the build path.
I can run my program outside of a jar file, but I want to deploy it and run it as a jar.
This command works for running the .class file:
java -classpath .;./libs/mail.jar;./libs/jcommon-1.0.16.jar;./libs/jfreechart-1.0.13.jar;./libs/jxl.jar;./libs/ojdbc5.jar gdsreports/ReportsDriver
This is how I package my jar file:
jar -cfvm GDSReports.jar GDSReports.mf gdsreports/* util/* libs/*
My manifest looks like this:
Manifest-Version: 1.0
Main-Class: gdsreports.ReportsDriver
Created-By: Me
This is how I run my jar:
java -classpath .;./libs/mail.jar;./libs/jcommon-1.0.16.jar;./libs/jfreechart-1.0.13.jar;./libs/jxl.jar;./libs/ojdbc5.jar;./util;./gdsreports -jar GDSReports.jar
However, run I run the jar file, it fails to load all the libraries. This is what it spits out:
Error loading configuration file: config/reportConfig
Error loading configuration file: config/gdsIds
Exception in thread "main" java.lang.NoClassDefFoundError: jxl/write/WriteException
at util.ReportConfig.setupReports(ReportConfig.java:197)
at util.ReportConfig.setup(ReportConfig.java:65)
at gdsreports.ReportsDriver.main(ReportsDriver.java:36)
Caused by: java.lang.ClassNotFoundException: jxl.write.WriteException
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)
... 3 more
This is the expected output:
Error loading configuration file: config/reportConfig
Error loading configuration file: config/gdsIds
-------------------------------------
Running TimingReport with parameters:
Filename: Reports/06-26-2012/TimingRptZL_06-26-2012.xls
Brand: ZL
Using production database: false
-------------------------------------
-------------------------------------
Exception in thread "main" java.lang.NullPointerException
at gdsreports.TimingReport.fillChartData(TimingReport.java:417)
at gdsreports.TimingReport.fillReport(TimingReport.java:238)
at gdsreports.TimingReport.run(TimingReport.java:131)
at gdsreports.ReportsDriver.main(ReportsDriver.java:40)
What am I doing wrong?
The -classpath argument (and the CLASSPATH environment variable) are ignored when you use the -jar argument.
If a jar file depends on other libraries, you have two choices:
Use the Class-Path header in your MANIFEST.MF file to call out the other jars, or
Unpack the other jars and include them in your jar.