I have a spring Boot application. I package it with maven, and I execute it with java -jar xxx.jar. The application is running. However if I copy the jar on another machine (same java version, same OS) I get a dependency error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration':...
...
Unsatisfied dependency expressed through constructor parameter 0
...
Bean instantiation via factory method failed
...
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [javax.sql.DataSource]:
Factory method 'dataSource' threw exception; nested exception is java.lang.NullPointerException
I added debug=true to show the classpath during execution, but it seems the same on both machines (there were issues with classpath order between maven execution and java execution)
EDIT: actually the problem is not changing machine: if I just move the jar in another folder, I get the same error. If I look at the correct running process it seems fairly obvious that in the classpath there are references to ther project target folder that cannot be satisfied...
Original machine is iOS, I tried the jar on other iOS and a Centos machine with same result.
I thought jar was very portable for deployment, so I don't understand if there is a better way of deploying the application or some environment variable I'm not taking into account
EDIT: I use maven. I do
mvn package
or
mvn clean install
and I have the dependencies mentioned in the answer
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
You need to create a Fat jar (a jar file with all the dependencies), you can find a more detailed info here, but to let some code in the answer:
Basically what you have to do is check that you have the right dependencies in your pom
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
</plugin>
</plugins>
Then you should do
mvn clean install
And run it!
java -jar <artifact-name>
EDIT
What do you see if you do a repackage? mvn clean package spring-boot:repackage
Your HibernateJpaConfiguration bean cannot be created. It looks it has some property declared in a #Configuration annotated class or in the application.properties resource file. Some property that has a relative path in it, and when you move the jar it cannot find that property.
Actually it was a trivial issue: a directory had to be listed from a relative path and in order to execute the jar somewhere else I had to just create that directory.
The error wasn't properly catched so the stacktrace was showing failure in dependencies and I missed the simple reality: java.lang.NullPointerException....
Thanks to #AndyWilkinson for making me read the stacktrace again...
Related
How to solve this error?
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
Suppose I don't have the liquibase installed. I just want to run my Spring project connected to postgres from maven/gradle/eclipse and I'm getting this error from all.
My maven configuration is using liquibase 4.9.1
I'm trying to use
db/changelog/db.changelog-master.xml
In My pom.xml I have
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<configuration>
<propertyFile>/src/main/resources/liquibase.properties</propertyFile>
<changeLogFile>/db/changelog/db.changelog-master.xml</changeLogFile>
</configuration>
</plugin>
What should I type in
cat src\main\resources\liquibase.properties
for classpath?
classpath:/db/changelog/db.changelog-master.xml
from eclipse I get
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException:
Error parsing classpath:/db/changelog/db.changelog-master.yaml
..
Caused by: liquibase.exception.ChangeLogParseException:
Error parsing classpath:/db/changelog/db.changelog-master.yaml
..
Caused by: liquibase.exception.SetupException:
The file db/changelog-base.xml was not found in
..
Specifying files by absolute path was removed in Liquibase 4.0.
Please use a relative path or add '/' to the classpath parameter.
..
Caused by: liquibase.exception.ChangeLogParseException:
The file db/changelog-base.xml was not found in
..
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
Could you please help me?
UPDATE:
It worked from maven when I updated the changeLogFile value.
$ mvn liquibase:update
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<configuration>
<propertyFile>/src/main/resources/liquibase.properties</propertyFile>
<changeLogFile>/src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
</configuration>
</plugin>
But how to run liquibase from eclipse, Java Spring boot project, I Run as java Application?
Basically I have a spring project that successfully run from eclipse, now with this liquibase configuration my application fails.
using
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml
in My application.properties
I have an issue when I use maven for installing an external jar from SAP.I'm using springboot and I've gotten 2 scenarios with no success.
1- Using maven dependency directly from folder I get an exception and the jar is not added in BOOT-INF/lib folder. But on eclipse the jar is added in Maven Dependency
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.19</version>
<scope>system</scope>
<systemPath>/home/eder/workspace/obsekium/TesteSelenium/sapjco3.jar</systemPath>
</dependency>
Caused by: java.lang.NoClassDefFoundError: com/sap/conn/jco/ext/DestinationDataProvider
2- Using "mvn install:install-file" Maven changes jar's name and it causes an exception
Factory method 'sapConector' threw exception; nested exception is java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco3-3.0.19-3.0.19.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar".
How do I solve this issue?
You can try to use the following dependency and check whether it works.
<dependency>
<groupId>com.sap.jco</groupId>
<artifactId>sapjco</artifactId>
<version>3.0.14</version>
</dependency>
You can find the details from the following link.
https://mvnrepository.com/artifact/com.sap.jco/sapjco/3.0.14
If you want, you can download the jar file and you can set the dependency as system path in maven.
My current project consisting of a war and ejb module, is using a jar (incorperated via maven). This jar contains a CDI component which, when I inject this in the war module it works as expected, but when I inject this in my ejb module I get a NoClassDefFoundError during startup from my WAS 8.5 in eclipse (full profile).
When I start the server first, add the inject later and republish it seems to work. Also when I use Liberty profile it works. Also on Z/os and IPAS it works as expected.
I think it might has something todo with classloading, but have no idea how to solve this properly.
Using Eclipse Neon, WAS 8.5.5.11 full profile , jee6
Project is using java 8 while the component is using java 6
This is the first part of the stacktrace:
[13-9-17 14:54:26:589 CEST] 0000003e InjectionProc W CWNEN0047W: Resource annotations on the fields of the BestelFacade class will be ignored. The annotations could not be obtained because of the exc
eption : Logger
at java.lang.Class.getDeclaredFieldsImpl(Native Method)
Thanks
I found a way to get the job done, but I'm not sure if this is a proper solution or just a workaround while masking the real problem.
When I take a look at the ear module assembly I see in the source column c:/ws/.../jar and in the deploy path lib/jar
when I change the source into /..ear/target/../jar it works
Try setting the <bundleDir>/</bundleDir>
This will place the external jar/ejb not in lib, but in the root.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
...........
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<jarModule>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<bundleDir>/</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
I'm trying to build a Maven-Eclipse project, which can handle many implementation.
Its a MVC project. I want a common controller, and to have two (or more) service/dao implementations.
The controller project has lots of interfaces for the other ones (Services, Daos, Entities).
I want something like this:
Currently, I have something more like this.
It "works" and generates working wars when build:package, but i can't make it work on Eclipse. I'm getting the error below when I start the Tomcat 7 (using JDK 7).
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'entityManagerFactory' defined in file
[D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\webapps\Impl1\WEB-INF\classes\spring-database.xml]:
Invocation of init method failed; nested exception is
java.lang.NoClassDefFoundError: ar/com/company/ml/core/entity/Publication
Publication is an interface in "Controller" project.
I'm using
org.eclipse.m2e.maven
Maven Integration for Eclipse JDT Annotation Processor Toolkit
Thank you and sorry for the images, I think they will be usefull.
Please help me organize this, or provide any good tutorial with this structure.
Controller POM:
<parent>
<groupId>ar.com.company</groupId>
<artifactId>Packer1</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>ControllerProject</artifactId>
Packer1 POM:
<groupId>ar.com.company</groupId>
<artifactId>Packer1</artifactId>
<version>3.0.0</version>
<packaging>pom</packaging>
<modules>
<module>ControllerProject</module>
<module>ServiceImpl1</module>
</modules>
I currently have the following in my application.properties:
liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
The actual path to the file is src/main/resources/db/changelog/db.changelog-master.xml.
The changelog is found by Liquibase and everything is working as I would expect.
I've moved the changelog and all of the project's JPA entities and repositories into a separate project so that they can be shared with other projects.
This second project is a Maven dependency of the first project. What path do I need to use in application.properties of the first project to access the liquibase changelog in the second project?
Update
I have:
projectA.jar -> pom.xml
<dependency>
<groupId>com.foo</groupId>
<artifactId>projectB</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
projectA.jar -> application.properties
liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
projectB.jar -> src/main/resources/db/changelog/db.changelog-master.xml
But I'm getting:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.xml] (please add changelog or check your Liquibase configuration)
I'm an idiot. My local ~/.m2 repository had an old version of the jar without the Liquibase changelog. A mvn clean install fixed the issue.