Liquibase has init project subcommand to get started with Liquibase.
Is it possible to run this command via the Liquibase Gradle Plugin?
If not, is it possible to generate a skeleton / empty databaseChangeLog file from Gradle script? Which I can use as my root changelog file to reference other generated changelogs.
I asked some of our development team about this, and they said that
Running init project with the Gradle plugin is untested
Even though we didn't test it, it might still work. Did you try running it yourself?
Are you looking for something to create an xml file with just the xsd headers and root element? They provided the XML below, if that's the case.
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"
>
</databaseChangeLog>
Related
I am getting the following liquibase error when I run my Spring Boot application:
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
Here is the class path in application.yaml:
liquibase:
change-log: classpath:db/changelog/db-changelog-master.xml
I also tried:
liquibase:
change-log: classpath:/db/changelog/db-changelog-master.xml
Here is folder structure:
Changlog master:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<include file="db-changelog-1.0.xml"/>
</databaseChangeLog>
I got this issue when putting the changelog files outside the resources folder, but if I include them under resources/db/changelog, then it would work fine with setting the bellow config.
spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml
Tested under 4.6.2
This is still an open issue unfortunately. See 2281.
Looks like this was fixed in v4.4.3
As explained here
How the Liquibase classpath worked before version 4.0
Before version 4.0, one of the default locations Liquibase added to
the classpath was the root directory in your filesystem (/). The
change caused issues because of a machine-dependent changelog path,
such as /home/my-user/projects/liquibase/changelog.xml, found under
the / directory. This way, Liquibase uses the given path as part of
the changeset identifier stored in the DATABASECHANGELOG table, and
when you run Liquibase from
/home/other-user/projects/liquibase/changelog.xml, Liquibase sees it
as a different changelog and tries to rerun all the previously run
changesets.
To prevent identification issues from happening, a / was removed as a
default part of the classpath. How the Liquibase classpath works in
4.0 and later versions
Starting with Liquibase 4.0, the root directory (/) is no longer a
default part of the classpath because of the issue mentioned in the
previous section.
...
The message "Please use a relative path or add '/' to the classpath parameter." refers to the root directory '/', and does not mean to add a slash to the start of your classpath path. Afaik, classpath:x and classpath:/x are the same.
Also, the message appears when the master changelog is not found, for whatever reason, so also a typo can cause this message. It's only a hint telling you that it might not be found because the file is not on the classpath, because they removed the root directory from the classpath, but it could also not be found because you specified the wrong path (I just did that).
To configure it correctly, the master changelog must be on the Liquibase classpath. In Spring Boot, the Liquibase classpath is set to the application's classpath, i.e. you can use src/main/resources.
Tl;dr: When your file is src/main/resources/db/changelog/db.changelog-master.xml use
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
I don't know, whether there was or is a bug in regards to that with certain Liquibase versions, but that's how it's supposed to work, anyway.
Just try to remove "classpath:" from "change-log:" parameter.
Also try to check your pom.xml ("changeLogFile" tag in configuration):
there should not be a "${basedir}" before change log file path.
<changeLogFile>
/src/main/resources/liquibase/changelog.xml
</changeLogFile>
I have no right to access the weblogic.Deployer stuff nor the web admin GUI (if that exists in Linux server version)
I can only upload file via FTP to a deployment folder (there are jsp/META-INF/WEB-INF sub folders) where the admin setup to us.
And the admin also provide us a script to restart the app server. (OS is linux)
I wonder if this is possible to unzip the WAR file and upload files to server and restart the app server to get it started?
I actually tried and unable to see any spring related stdout and logs. The app server only show not found in web browser. just like the application does not exist at all.
I can deploy the WAR file in weblogic (windows edition). the app files should be ok.
You should be able to deploy the exploded Spring Boot WAR to the folder.
But it's import that you change the context path in application.properties to match the context path the app will run under in Weblogic:
server.servlet.context-path=<the context path>
META-INF\maven\com.example\demo\pom.properties
\pom.xml
\MANIFEST.MF
org\springframework\boot\loader\some folders and classes
WEB-INF\classes\com\example\demo\RootController.class
\ServletInitializer.class
\DemoApplication.class
\application.properties
\lib\and some jars
\lib-provided\and some jars
\dispatcherServlet-servlet.xml
\weblogic.xml
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:context-root>/</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<!-- added these after some google -->
<wls:package-name>javax.validation</wls:package-name>
<wls:package-name>org.hibernate.validator</wls:package-name>
<wls:package-name>javax.el</wls:package-name>
<wls:package-name>javax.persistence</wls:package-name>
<!-- added above after some google -->
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
I have a requirement in my project where I want to read files into table CLOB data. The database is oracle 12g. We are using liquibase to maintain the data.
The project is in springboot. Liquibase uses .sql files to load changes.
The hurdle I am facing is that sql needs the absolute path to the file rather than the path relative to the current changeset file.
Any pointers about how I can use a "." or the "classpath:" in the sql of the changeset?
One of the attempts I have made are sending a property in the changeset through the property tag withen the databaseChangeLog tag. Values of such properties are available in the changeset file, but they dont interpret placeholders like "classpath:". Hence I am stuck.
The
dbms_lob.fileopen
only accepts a directory object with the absolute path. No "." etc is understood. The . in a filepath starts at the database installation root which is of no use to me. I would like the path to where all the changeset files are stored.
Please help If you have solved this in any way..
I will post more details if required..
Appreciate the help..
As example what work for me: i'va put this argument on command line as reference for the master changelog
--changeLogFile=src/main/resources/changelog/db.changelog-master.xml
and in the master file
<include file="./changes/db.changelog-ddl-.....xml" relativeToChangelogFile="true"/>
It will be the same for sql file in changeset - they will be referenced relative to the .xml
What about setting up a directory object in oracle in advance and then use symbolic linking on OS level. Depending on your exact requirements you can use symbolic linking on directory level, or you can even directly link the files into the oracle directory, so that Oracle can see files from many different directories at once in the directory object. They need to have different filenames then. I have not tried this idea, but I guess this approach is what I would try out first. HTH KR
Liquibase supports properties in changelogs that can be set in various ways - more information:
http://www.liquibase.org/documentation/changelog_parameters.html
Here is a snippet of that documentation:
Liquibase allows dynamic substitution of parameters in a changelog.
The parameters to replace are described using the ${} syntax.
Parameter values are looked up in the following order:
Passed as a parameter to your Liquibase runner (see Ant, command_line, etc. documentation for how to pass them)
As a JVM system property
In the parameters block ( Tag) of the DatabaseChangeLog file itself.
Example of how could be used:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<property name="clob.type" value="clob" dbms="oracle"/>
<property name="clob.type" value="longtext" dbms="mysql"/>
<changeSet id="1" author="joe">
<createTable tableName="table1">
<column name="id" type="int"/>
<column name="${columnname}" type="varchar(20)"/>
</createTable>
</changeSet>
easily you can set file path inside SQL change-set via a property while property value passed with JVM or Build-tools.
#echo off
call Liquibase --changeLogFile=myChangeLogFile.xml update -Dcolumnname=myclm
However I think you can use ${java.class.path} without set it's value from outside.
Summary/Question
I've rolled onto a project that uses ehcache. The project is maven enabled and when I run mvn clean install from cli all ends well.
The project can also be opened in NetBeans and everything displays properly, however when I open the project in eclipse, I'm seeing some errors related to ehcache. In NetBeans the spring-cache.xml is located under a "Web Pages" folder. This made me think that the eclipse project may not be recognized as a dynamic web project, however following the directions here: https://www.mkyong.com/java/how-to-convert-java-project-to-web-project-in-eclipse/ I was able to verify that the project is indeed setup to support Dynamic Web Module, Java and JavaScript.
I also opened the project in IntelliJ and also did not see any issues with the spring-cache.xml.
I also didn't find documentation related to this version of ehcache on http://www.ehcache.org/documentation/ but the fact that things work in NetBeans, IntelliJ and via mvn clean install make me think its my eclipse setup. Thoughts?
More Details:
The errors I see in eclipse are:
Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.
- schema_reference.4: Failed to read schema document 'http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring-1.1.xsd, because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
And
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:config'.
My maven dependency looks like:
<dependency>
<groupId>com.googlecode.ehcache-spring-annotations</groupId>
<artifactId>ehcache-spring-annotations</artifactId>
<version>1.2.0</version>
</dependency>
Which matches what it should be, based on: https://mvnrepository.com/artifact/com.googlecode.ehcache-spring-annotations/ehcache-spring-annotations/1.2.0
My spring-cache.xml file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">
<ehcache:annotation-driven />
<ehcache:config cache-manager="cacheManager">
<ehcache:evict-expired-elements interval="60" />
</ehcache:config>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="${ehcache.config.location}"/>
</bean>
</beans>
Looks like current versions of NetBeans and IntelliJ aren't as strict on checking things as eclipse is. :) The following is what I found out.
From ehcache with Spring. google code xsd file not found I found out that the top error was related to the fact that the xsd is no longer hosted at the url provided.
Doing some googles, I found a reference to the version on github at: https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.2.xsd by changing my bottom xsi schemalocation to the above url, it resolved the issue in eclipse.
The stack overflow questions referenced, also provides a link to the google code archive of: https://code.google.com/archive/p/ehcache-spring-annotations/source/default/source
If you download the zip, you can then find the offical xsd in the zip at: /schema/ehcache-spring/ehcache-spring-1.2.xsd (it also has ehcache-spring-1.0.xsd and ehcache-spring1.1.xsd in case anyone else has issues with even earlier versions).
I found a way to reference the local schema file here: How to reference a local XML Schema file correctly?
I'm going to post a question on how to reference it from a relative path of the project, as we have both windows and mac developers on this project. If this is of use to you, the details will be here: How to Reference Local XSD File By Relative Path
Summary of issue:
xsi-schemaLocation reference:
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
results in validation-issues in eclipse, on commandline maven there are no issues.
replacing the ref with:
https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd
solves issue in eclipse. In maven the saxparser will complain however if you 're not connected to internet.
By putting a proxy ref :
-Dhttp.proxyHost=[proxyhost] -Dhttp.proxyPort=[proxyport] -Dhttps.proxyHost=[proxyhost] -Dhttps.proxyPort=[proxyport]
the maven build succeeds....
I investigated this difference in behaviour:
in the ehcache-spring jar, ehcache-spring-annotations-1.1.2.jar,
a META-INF/spring.schemas file is present.
Content of that file:
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.0.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.0.xsd
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd
cmdline maven uses this content (and finds the xsd in the jar).
eclipse does not.
Solution I used:
go to eclipse preferences,
XML -> XML Catalog and add a new user entry:
Location: https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd
Key type: Public id
Key: http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
Alternative web adress: https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd
Re-validating spring context files solved issues in my eclipse workspace.
I like this solution better because it is a shortcoming of eclipse which i solve with an eclipse-specific solution.
I was following the following basic spring batch tutorial https://spring.io/guides/gs/batch-processing/ .
I am using IntelliJ 14 and created a Spring-Batch project
I am using Mavin. And I have pom.xml file.
I haven't created any file except under src/main/resources/sample-data.csv.
I didn't create any DB or JDBCTemplate since I assume it is not needed since the tutorial uses in Memory DB.
Mvn clean install works fine even though the Application.java shows me "Couldn't autowire. No beans of jdbcTempalte type can be found"
#Autowired
JdbcTemplate jdbcTemplate;
Spring-config has the following
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
I am getting an error when I try to do mvn spring-boot:run
The cause by shows Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: PEOPLE
What am I missing? I appreciate your help.
You should put schema initialisation in your src/main/resources. Spring batch automatically runs schema-##platform##.sql during startup and -all tells it to be for all platforms as noted in readme.adoc on github:
Next, you write a SQL script to create a table to store the data.
src/main/resources/schema-all.sql
link:initial/src/main/resources/schema-all.sql
Note: Spring Boot runs
schema-##platform##.sql automatically during startup. -all is the
default for all platforms.
If you want to run a Spring Batch without database configuration then you can use
#SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
More details can be found on thread Spring-Batch without persisting metadata to database?