How do I use a Liquibase changelog which is in jar file - java

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.

Related

How to get rid of Liquibase 4.0 error : Please use a relative path or add '/' to the classpath parameter

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

Logging system failed to initialize using configuration from 'classpath:logger/logback-spring.xml'

I use Spring boot 2.3.0.RELEASE.
application.properties
spring.profiles.active=dev
logging.config=classpath:logger/logback-spring.xml
logging.file.dir=reception-electronic-docs
logging.file.name.var=reception-electronic-docs.log
logging.file.archive.format.name=reception-electronic-docs.%d{dd-MM-yyyy}.log
Previously this code worked (Srping boot 2.2.5.RELEASE).
I use multi module structure in the project. But there, the Central pom does not manage the entire project. I create microservices.
During start up an application encounter an error:
Logging system failed to initialize using configuration from 'classpath:logger/logback-spring.xml'
java.io.FileNotFoundException: class path resource [logger/logback-spring.xml] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137)
What are any ideas to correct this?
I add an dependencies
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.2</version>
</dependency>
But I don't understand reason.
After I removed the dependency. But my app runs without errors. I'm at a loss.

Installing JCOSap using maven on springboot

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.

(springboot) jar not executable on other computers

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...

Maven- Could not resolve dependency

I am a beginner in using Maven.. I tried to add Grobid (for pdf parsing) in maven. The dependency I gave is :
<dependency>
<groupId>org.grobid</groupId>
<artifactId>grobid-core</artifactId>
<version>0.3.4</version>
</dependency>
But on building the pom it shows the following error:
[ERROR] Failed to execute goal on project Miner: Could not resolve dependencies for project Miner:war:1.0-SNAPSHOT: Failed to collect dependencies at org.grobid:grobid-core:jar:0.3.4 -> org.chasen:crfpp:jar:1.0.2: Failed to read artifact descriptor for org.chasen:crfpp:jar:1.0.2: Could not transfer artifact org.chasen:crfpp:pom:1.0.2 from/to 3rd-party-local-repo (file:///${basedir}/lib/): Repository path /${basedir}/lib does not exist, and cannot be created. -> [Help 1]
I have gone through different questions related..I tried after adding pom etc. Still it is not working.. why this error comes..do we have to do extra codes for Grobid..?
add the below repository in pom or .m2/settings.xml
<repositories>
<repository>
<id>Grobid repository</id>
<url>https://mvnrepository.com/artifact/org.grobid/grobid-core</url>
</repository>
</repositories>
Start by downloading maven from http://mirror.vorboss.net/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip
Unzip it somewhere, then assuming your're on windows
1) set an environment variable M2_HOME to point at the unziped folder.
2) add %M2_HOME%/bin to your PATH environment variable
3) go to your home directory (probably C:/Users/????? and create a .m2 folder
4) move the settings.xml file from the maven unzippped/conf directory to the directory created in step 3.
5) you may have to set the proxy element correctly in your settings.xml file
It should work.
You might be new to maven, but it explicit the problem here:
Repository path /${basedir}/lib does not exist, and cannot be created.
This means that Maven could not locate the repository path you are trying to access. Or (from the "cannot be created") can't find the directory where to save the content.
As you did not provide pom.xml to look further, you'll have to find all ${basedir}/lib path in your pom.xml and in your maven settings (default to %USERPROFILE%/.m2/settings.xml or $HOME/.m2/settings.xml), then you may want to
try with an absolute path.
use an actual HTTP repository where that dependency and child' dependencies are.
use a repository server such as Sonatype Nexus or Archiva and provide a mirror/copy of it.

Categories

Resources