I am trying to run a Hibernate application. I can do it from NetBeans IDE, when I am going to command line, with mvn install it builds successfully but when I am trying to run the jar file in target folder (java -jar hibernate-1.0-SNAPSHOT.jar) I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
at hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:11)
at hibernate.SmartDevice.main(SmartDevice.java:13)
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
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)
... 2 more
It doesn't find the Configuration class of Hibernate, but I added the hibernate-core dependency in 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>hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.1.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>hibernate.SmartDevice</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<name>hibernate</name>
</project>
Here is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="hibernate.User"/>
</session-factory>
</hibernate-configuration>
Should I add something else? Or why is this error? Thanks for the help!
ClassNotFoundException means that the org.hibernate.cfg.Configuration class in not included in your classpath. Looking for that class in the IDE, we see it is included in the hibernate-core-5.4.1-Final.jar file.
By running java -jar hibernate-1.0-SNAPSHOT.jar, the additional dependencies are missing.
There are some ways to package your jar with the required dependencies, one is by using the maven-assembly-plugin, or by using the shade plugin.
As a "manual" alternative, you can cd to your project root folder (containing the pom.xml file), and execute
mvn clean package
mvn dependency:copy-dependencies
java -cp target/*;target/dependency/* hibernate.SmartDevice
The dependency plugin copies all needed jars to the target\dependency folder, and the last command adds all jars to the classpath and runs your java class.
edit the above commands are for Windows; on Linux you would use ":" in place of ";"
Related
I just finished building an application using JavaFX and Hibernate, which builds and run perfectly on IntelliJ, so I choose to generate a "fat-jar" using maven shade plugin, since I make use of some libraries with automatic module names, so I cannot use jlink.
Jar is created fine, it loads the initial screen correctly, however when it tries to make connection to my database, specifically this line is the problematic (JPAUtil.java:19);
factory = Persistence.createEntityManagerFactory(persistenceUnit, properties);
I get the following exceptions;
java.lang.IllegalStateException: Required class information is missing
at org.jboss.jandex.Indexer.rebuildNestedType(Indexer.java:926)
at org.jboss.jandex.Indexer.resolveTypePath(Indexer.java:786)
at org.jboss.jandex.Indexer.resolveTypeAnnotation(Indexer.java:705)
at org.jboss.jandex.Indexer.resolveTypeAnnotations(Indexer.java:613)
at org.jboss.jandex.Indexer.index(Indexer.java:1602)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:64)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:52)
at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:147)
at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:48)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:76)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:254)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:175)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:171)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:119)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at com.it.util.JPAUtil.getEntityManagerFactory(JPAUtil.java:19)
at com.it.controller.HomeController.initializeSettings(HomeController.java:1571)
at com.it.controller.HomeController.initialize(HomeController.java:1407)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2573)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at com.it.Home.start(Home.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
I know the syntax is correct as I mentioned before it runs correctly on IDE, so I suspect it is something missing on the jar file generated by shade, however I've spend almost 3 days on this already and I simply cannot find a reason. Information shown on the stacktrace doesn't help much, at least I don't see anything - I did even looked to all classes mentioned on the stacktrace and they all seem to be on the generated Jar.
Hoping anyone here had something similar or is maybe more familiar than me on the maven shade process. Any help or point to look at would be appreciated.
Additional files which would help to identify the problem is as follow;
persistence.xml - other properties are loaded from a XML file on the code.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="Project-Postgre">
<description>Hibernate JPA Configuration</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value = "false" />
</properties>
</persistence-unit>
</persistence>
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.it</groupId>
<artifactId>Project</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>14</javafx.version>
</properties>
<name>Project</name>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/de.jensd/fontawesomefx -->
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.20.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc10 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc10</artifactId>
<version>19.7.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>com.it.HomeFX</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>project-classifier</shadedClassifierName>
<outputFile>target\shade\${project.artifactId}.jar</outputFile>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.it.HomeFX</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
JPAUtil
public static EntityManagerFactory getEntityManagerFactory(String persistenceUnit, String connectionURL, String user, String password) {
if (factory == null) {
Map<String, String> properties = new HashMap<>();
properties.put("javax.persistence.jdbc.url", connectionURL);
properties.put("javax.persistence.jdbc.user", user);
properties.put("javax.persistence.jdbc.password", password);
factory = Persistence.createEntityManagerFactory(persistenceUnit, properties);
}
return factory;
}
I had the same error using:
spring.version:5.2.7.RELEASE
spring.boot.version:2.3.1.RELEASE
postgresql-version:42.2.16
It happens with all versions of postgres from 42.2.15. Version 42.2.14 (or earlier) works fine for me.
I had the same problem. I tried to downgrade PostgreSQL JDBC driver version to 42.0.0. Exception gone and everything works fine.
The issue is caused by invalid bytecode produced by javac 1.8 (e.g. AdoptOpenJDK 1.8u222 is known to be affected).
Here's the issue (with reproducer): https://github.com/wildfly/jandex/issues/92
The fix is to update to org.jboss:jandex:2.2.3.Final which includes the workaround (and a couple of other fixes for type annotations), or use Java 11 compiler (== javac 11).
Just in case, org.postgresql:postgresql:42.2.15 triggers the issue since it uses the Checker Framework for nullness verification, and it includes multiple #Nullable and #NonNull annotations to make the verifications pass.
The upcoming org.postgresql:42.2.18 and org.postgresql:42.3.0 will have the relevant workarounds, so it would work with old jandex versions as well.
If you are reading here, I would recommend adding forbidden-apis and jandex bytecode parsers (e.g. de.thetaphi.forbiddenapis and com.github.vlsi.jandex Gradle plugins) to your build pipeline to capture invalid bytecode early (which might otherwise come unnoticed), especially if you still use javac 1.8.
I have managed to overcome this issue by switching from Hibernate to OpenJPA.
Hibernate did not provide enough information to debug the problem and when switching to OpenJPA I just had to add this to my pom.xml;
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-all</artifactId>
<version>3.1.2</version>
</dependency>
Shade created the JAR with all required libraries and connection to database was successfully.
Eventually, fixed in PostgreSQL JDBC Driver version 42.2.19, see https://jdbc.postgresql.org/documentation/changelog.html#version_42.2.19.
Update your version to 42.2.19 and it should solve the problem.
I am using Maven to compile and package a Java application from the command line:
mvn clean
mvn compile
mvn package
These commands run without a problem. But when I try to run the generated JAR file
java -jar target/JarFile.jar
I get the following error:
Error: Unable to initialize main class com.company.Main
Caused by: java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
Which is a class from an external dependency. These dependencies are also managed by Maven (i.e., I am not supplying them locally, but listing them in my POM file.) Since I am able to run the application inside the IDE, I assume I am missing a step to make the dependencies available to the JAR file. Here is my POM file:
<?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>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<groupId>test-maven-project</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.30.6</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.34.2</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.30.9</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>1.34.2</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-customsearch</artifactId>
<version>v1-rev20200401-1.30.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.company.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Could you point me in the right direction so that the dependencies are accessible at runtime?
To run your jar from commandline, you must either explicitly specify the classpath on the command line or build an executable jar:
How can I create an executable JAR with dependencies using Maven?
BTW: mvn package already executes mvn compile, so you need not call mvn compile explicitly.
Use this in your pom.xml and rebuild your project.
<dependency>
<groupId>com.google.api.client</groupId>
<artifactId>google-api-client-json</artifactId>
<version>1.1.0-alpha</version>
</dependency>
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.
My Java application contains three class files with dependencies
Master.java
Worker.java
EmailSender.java
I have packaged my application using maven.
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.myapp.urlhit</groupId>
<artifactId>url_hit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>url_hit</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.myapp.urlhit.url_hit.Master</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
and below are my manifest file contents
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: venkat
Build-Jdk: 1.8.0_45
Main-Class: com.myapp.urlhit.url_hit.Master
Class-Path: mailapi-1.4.3.jar jsoup-1.8.2.jar activation-1.1.1.jar
when I am trying to execute the packaged JAR file using java -jar ###.jar
I am getting the error like
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/nodes/Element
at com.myapp.urlhit.url_hit.Master.main(Master.java:14)
Caused by: java.lang.ClassNotFoundException: org.jsoup.nodes.Element
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)
... 1 more
above error is referring to line
Worker works = new Worker();
the packaged jar contains all the required class files. But still I am facing this error. I have nothing in my echo $CLASSPATH.
Because jsoup 1.8.2 download to your local repository corrupted.
- Check network connection
- Try again or use other version
- Try other maven repository URL.
- Download dependency manually then add it to local Maven repository.
I want to integrate a leap motion app into Weasis Dicom Viewer.
Projects:
Weasis-maven-plugin -> where my leap implementation is
Weasis-framework -> dicom viewer
Weasis-launcher -> This is where I launch the Dicom viewer.
What I've done already:
have m2e with eclipse and added the LeapJava.jar to plugin project and set the location of the native library
installed LeapJava.jar into the .m2/repository folder so that mvn install on my maven plugin build succeeds
added into the pom.xml of maven-plugin
updated maven project
what doesn't work:
when i launch the application, I get no LeapJava in java.library.path
I've seen some other threads that says I need to manually add -Djava.library.path to the VM arguments. However, when I add that to the launcher run config in eclipse the library not found still exists. Should I be adding this somewhere? Any help is greatly appreciated.
This is my pom.xml for the weasis-plugin:
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>weasis-parent</artifactId>
<groupId>org.weasis</groupId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../../weasis-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>LeapPlugin</groupId>
<artifactId>UBC</artifactId>
<packaging>bundle</packaging>
<name>Tool panel sample [${project.artifactId}]</name>
<properties>
<bundle.symbolicName>${project.artifactId}</bundle.symbolicName>
</properties>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Service-Component>OSGI-INF/*.xml</Service-Component>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-ui</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.dicom</groupId>
<artifactId>weasis-dicom-viewer2d</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/sdk/LeapJava.jar</systemPath>
</dependency>
</dependencies>
When I add the "systemPath" I can still mvn install properly but when i run the launcher project now I get org.osgi.framework.BundleException: "Unresolved constraint in bundle"
UPDATE 1:
So right now this is what my pom.xml looks like
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no leapMotion-1.0.0 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at weasisTool.SampleTool$1.run(SampleTool.java:98)
Not sure if this is the actual solution.
But I added:
nativedependency-plugin in my pom.xml
made sure to do mvn package on the plugin project folder (this generated some files under target/ folder
added -Djava.library.path to the VM argument and it compiles and runs!