I have created a sample plugin application using RCP framework using Hello RCP framework. Then, I converted the project into Maven project in "configure" option. I need a mysql connector to perform some db operation; for that I have added the dependencies in the pom.xml file.
After building the application, it's able to create the maven dependency folder and put the required mysql jars. However, when I run the application it says its not able to find the Driver class. There is no error in the jar file which is there in Maven Dependency folder. If I manually put it in the build path its working fine.
Whenever I create a sample JAVA application and convert it into maven project and add these dependencies its working fine. Only for plug in project its not able to locate the jars required.
Below is the content of my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.plugin</groupId>
<artifactId>com.sample.plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
<scope>Compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
//Error message
Inside the connection class1:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Error: unable to load driver class!
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.sample.plugin.DButil.getConnection(DButil.java:25)
at com.sample.plugin.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Picked up _JAVA_OPTIONS: -Xmx512M
Download mySQL jdbc driver, if not already done
Add this to your local repository (Due to licensing issues, you must download, you cannot download it from Maven public repository)
Make sure you mark the dependency as runtime, since we do not require driver jar during compile. Javac compiles to the JDBC API interfaces.
Related
I wrote a code for word count but when I tried running it from CMD in windows using below command it throws an exception.
spark-submit --class com.sample.WordCount --master local file:///E:/WordCountSample/target/WordCountSample-0.0.1-SNAPSHOT.jar file:///C:/Users/siddh/OneDrive/Desktop/sample.txt
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SparkSampleInScala</groupId>
<artifactId>WordCountSample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>WordCountSample</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!--<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M1</version>
</plugin> </plugins> </build> -->
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.12</artifactId>
<version>2.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scala-lang/scala-library -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.8</version>
</dependency>
</dependencies>
</project>
but when I ran spark submit it throws below error:
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: scala/runtime/java8/JFunction2$mcIII$sp
at com.sample.WordCount$.main(WordCount.scala:22)
at com.sample.WordCount.main(WordCount.scala)
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.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:849)
at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:167)
at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:195)
at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)
at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:924)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:933)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.NoClassDefFoundError: scala/runtime/java8/JFunction2$mcIII$sp
... 14 more
Caused by: java.lang.ClassNotFoundException: scala.runtime.java8.JFunction2$mcIII$sp
So what all needs to be done in this case?? I am using spark 2.4.0 version and scala 2.12.8 version which is already installed on my windows.
Please help me since I am stuck in this since few days.
Thanks in advance :)
looks like you are using 2.4.x with Scala 2.12. It might be compatibility issue.
Spark documentation reference:-
Spark runs on Java 8+, Python 2.7+/3.4+ and R 3.1+. For the Scala API, Spark 2.4.0 uses Scala 2.11. You will need to use a compatible Scala version (2.11.x).
I had the same issue, and solved it by changing the version of Scala I use during development to match the version Spark came with.
When I start Spark with ./spark-shell, it says Using Scala version 2.11.12,
So I changed the Scala version in the build.sbt from 2.12.8 to 2.11.12 and everything worked.
I use Spark version 2.4.3.
The other answers are correct.
To add to them, don't forget to update the jar path in the spark-submit command when you change Scala versions. So if you're using sbt it's:
Update the Scala version to be compatible with Spark.
sbt package
Update the jar path in the spark-submit command. In my case it went from target/scala-2.12/word-count-app_2.12-1.0.jar to target/scala-2.11/word-count-app_2.11-1.0.jar.
I have tried to include all the jars needed in Referenced Libraries.
There are similar questions on this forum, I have gone through all but unable to resolve the issue.
My Code Snippet:
Workbook workbook = new XSSFWorkbook();
CreationHelper createHelper = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet("Gene");
Font headerFont = workbook.createFont();
All the jars that I am using
I am getting following errors:
Exception stack trace:
org.apache.poi.ooxml.POIXMLException: org.apache.poi.ooxml.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.ooxml.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:602)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.createSheet(XSSFWorkbook.java:896)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.createSheet(XSSFWorkbook.java:807)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.createSheet(XSSFWorkbook.java:122)
at DomParser.main(DomParser.java:18)
Caused by: org.apache.poi.ooxml.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.ooxml.POIXMLFactory.newDocumentPart(POIXMLFactory.java:111)
at org.apache.poi.ooxml.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:587)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)
at org.apache.poi.ooxml.POIXMLFactory.newDocumentPart(POIXMLFactory.java:109)
... 5 more
Caused by: java.lang.NoSuchMethodError: org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl.generatedSetterHelperImpl(Lorg/apache/xmlbeans/XmlObject;Ljavax/xml/namespace/QName;IS)Lorg/apache/xmlbeans/XmlObject;
at org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl.setColsArray(Unknown Source)
at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.cleanColumns(ColumnHelper.java:66)
at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.<init>(ColumnHelper.java:46)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentCreate(XSSFSheet.java:259)
at org.apache.poi.xssf.usermodel.XSSFSheet.<init>(XSSFSheet.java:187)
... 11 more
You need to use xmlbeans-3.0.1 instead of xmlbeans-5.1.3.
Starting from the error, which was:
Caused by: java.lang.NoSuchMethodError: org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl.generatedSetterHelperImpl(Lorg/apache/xmlbeans/XmlObject;Ljavax/xml/namespace/QName;IS)Lorg/apache/xmlbeans/XmlObject;
I searched the Maven Central Repository for jars containing the class CTWorksheetImpl:
https://search.maven.org/search?q=fc:org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl
The answer was poi-ooxml-schemas, which you already had, and was the same version as poi. Seemed OK. Then I thought it had to be the method itself. The parameters were from the org.apache.xmlbeans package, so the xmlbeans version was probably wrong.
How can you find out the right version?
Rather than gathering jar files manually, you may want to try Maven for dependency management. In a Maven project, it would be enough to say you want poi-ooxml. This would automatically bring in all the dependencies, recursively, with the right versions.
This is an example Maven pom.xml file you could use your project:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>poi-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Even if you don't want to (or can't) use Maven in your project, you could at least do a separate project just for finding out the dependencies, like I did.
I have a problem that I can't seem to resolve. I have no issues starting a Spring Boot application from Eclipse (Oxygen) with STS 3.9.2, from the Boot Dashboard:
However, when I try to run it from command line, I get an error that files are missing:
Exception in thread "main" java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:62)
at java.lang.Thread.run(Thread.java:748) Caused by:
java.lang.reflect.InvocationTargetException 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.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54)
... 1 more Caused by: java.lang.ArrayStoreException:
sun.reflect.annotation.TypeNotPresentExceptionProxy at
sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
at
sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
at
sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
at
sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at
sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at
sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.createAnnotationData(Class.java:3521) at
java.lang.Class.annotationData(Class.java:3510) at
java.lang.Class.getAnnotations(Class.java:3446) at
org.springframework.core.type.StandardAnnotationMetadata.(StandardAnnotationMetadata.java:68)
at
org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition.(AnnotatedGenericBeanDefinition.java:56)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:139)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:127)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:122)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:158)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:134)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:126)
at
org.springframework.boot.SpringApplication.load(SpringApplication.java:708)
at
org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:357)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
at se.itab.bos.admin.AdminServer.main(AdminServer.java:37) ... 6
more
I tried commenting out the following from my startup class:
#SpringBootApplication
#Import({
// AppConfig.class
// , ActiveMqServerConfig.class
// , MetricConfig.class
// , AdminConfig.class
// , SystemConfig.class
// , SystemMessageRouterConfig.class
// , CommandConfig.class
// , AdminMessageRouterConfig.class
})
public class AdminServer {
This solves the issue so that I can launch from command line, but I don't understand why. In my pom.xml I have every other module defined, in which these files are contained.
I am using Spring Boot Starter 1.3.5.RELEASE and Java 8.
Any help would be greatly appreciated.
UPDATED
This is my full pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>se.bos</groupId>
<artifactId>bos-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../bos-parent</relativePath>
</parent>
<artifactId>bos-admin</artifactId>
<packaging>jar</packaging>
<name>BOS Admin</name>
<properties>
<java.version>1.7</java.version>
<start-class>se.bos.admin.AdminServer</start-class>
</properties>
<dependencies>
<!-- operations: spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency>
<!-- operations: spring boot admin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<!-- application: bos -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-site</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-server</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-core</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-client</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-model</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-system</artifactId>
</dependency>
<!-- application: spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- test -->
<!-- -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
To start the project from command line, I run:
mvn clean install
java -jar target/admin.jar
After commenting out each import one by one, I also found that the problem stems from imported modules, but have not yet found why.
Running java -version from command line:
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
This is the same as what is used in Eclipse and what is in JAVA_HOME
Using mvn clean install will not produce the executable jar file for you, as this will not package the executable spring boot libraries and pom dependencies. It will only produce a jar file containing only your code.
Using the spring-boot-maven-plugin you need to execute the spring-boot:repackage goal and phase in order for the executable jar file to be appropriately packaged with the spring boot/pom dependencies and ready to be executed on the command line. i.e. run mvn package spring-boot:repackage and then run your application on the command line.
Full details on this can be found in the Spring Boot Maven Plugin Documentation and the spring-boot:repackage goal.
Note: It works in Eclipse because Eclispe has setup your classpath appropriately to reference the dependencies in your pom at compile and runtime, whereas your compiled jar file does not.
I'm trying to install the Deeplearning4j library ( https://deeplearning4j.org/index.html) but I don't understand how to use install the lib correctly with IntelliJ and Maven so that I can build a .jar file from it.
As long as I'm running the program from IntelliJ everything seems to work.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>DeepLearning</groupId>
<artifactId>deeplearning</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-core -->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-api -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native-platform -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.datavec/datavec-api -->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>MLPClassifierLinear</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I am not sure if everything is set up correctly because it's the first time I use maven.
When I run the maven install command and start the .jar file I get an error that says that a JNI error has occurred and a NoClassDefFoundError.
This is the exact error message:
Error: A JNI error has occurred, please check your installation and
try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/deeplearning4j/nn/conf/layers/Layer 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:
org.deeplearning4j.nn.conf.layers.Layer 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
Can somebody explain me how to use maven correctly so I can build .jar files without getting errors?
Thank you :)
Simple recipe for getting most things done:
deeplearning4j-core, nd4j-native-platform, maven shade plugin
deeplearning4j-core gives you most dependencies people use on simple desktop.
nd4j-native-platform bundles all operating system native dependencies so you don't have to worry about multi OS deployments/binaries. This also makes sbt and gradle actually..usable since they can't handle classifiers.
maven shade plugin handles building the jar properly.
https://github.com/deeplearning4j/dl4j-examples/blob/94568e78e86c56807c03fe17d6a2f89f0b0df377/dl4j-spark-examples/dl4j-spark/pom.xml#L98
Also, please don't use the term "install". You aren't installing anything. You're setting up a set of libraries using a dependency manager. It's not installing in the sense of the OS like ruby and python tend to do.
Beyond that: Specific critiques about your pom. nd4j-native here is redundant. You don't need that. You only use nd4j-native if you are using snapshots or building from source.
Datavec-api isn't needed because it's already brought in by deeplearning4j-core. Please read up on maven transitive dependencies to understand how this works.
If you aren't sure on how any of these things get resolved, look at using
mvn dependency:tree
Currently my NetBeans 8.0 has been doing the strangest thing.
I have a multimodule project. Usually I did not even have to have the projects opened or even downloaded, if the modules were in maven repository. Currently, some of my modules however need to be opened and built, so that "target" folder is in the project directory filled with classes. If it is not, I get a NoClassDefFoundError.
The error looks like this:
Exception in thread "main" java.lang.NoClassDefFoundError: SOME/CLASS/THAT/IS/EXPECTED/IN/TARGET/FOLDER/OF/SOME/MODULE/THAT/IS/A/DEPENDENCY
at ...
Caused by: java.lang.ClassNotFoundException: com.example.SOME.CLASS.THAT.IS.EXPECTED.IN.TARGET.FOLDER.OF.SOME.MODULE.THAT.IS.A.DEPENDENCY
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
My POM looks like this:
<parent>
<groupId>some</groupId>
<artifactId>parent</artifactId>
<version>0.9-SNAPSHOT</version>
</parent>
<scm>
<developerConnection>scm:svn:https://someconnection</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagBase>sometagbase/tags</tagBase>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>myModuleGroupId</groupId>
<artifactId>somModule1</artifactId>
<version>1.2.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
...... many of these here
</dependencies>
Why does it suddenly require a target folder with classes? Is it not supposed to get them from the dependencies? From the repository?
Open maven tab at right side of the editor and run double click all options of life cycle and try to see if folder finally generated