liquibase / liquibase-docs

8 stars 18 forks source link

Don't use `java -jar liquibase.jar` syntax #138

Closed nvoxland closed 2 years ago

nvoxland commented 2 years ago

Description

Liquibase doesn't support using java -jar liquibase.jar. We should always be pointing people to just run the liquibase launch script.

These were the only places I saw java -jar used for liquibase. There are other places that use java -jar for starting h2 which may be better as liquibase init start-h2 now, but I'll open a separate ticket for that.

Additional Content

It may also be worth adding a new page about running liquibase without the launch scripts. I'm not sure where that would go so will leave that to someone else to add to this PR.

The stub content would be something like:

Liquibase ships with a liquibase/liquibase.bat launch script which configures Java to run the CLI. That launch script is the best way to run the CLI. When ran, it will:

  1. Choose the correct version of java a. If you have a JAVA_HOME environment variable set, it will use the java version there b. If not, if you installed the CLI via an installer, it will use the version of java bundled with the installed Liquibase c. If not, it will use the Java configured in your PATH environment variable
  2. Set up the classpath to include the main liquibase.jar plus what it finds in ./liquibase-libs plus what it finds in LIQUIBASE_HOME/lib
  3. Includes any additional java arguments set in JAVA_OPTS
  4. Runs the liquibase.integration.commandline.LiquibaseCommandLine class

If you do not want to run the liquibase launcher, you can set up the call to java using the pieces of that logic which you need. For example, java -cp <your classpath> liquibase.integration.commandline.LiquibaseCommandLine <liquibase args>.

NOTE: we don't support java -jar liquibase.jar because Java does not allow both -jar and -cp being set, and you need control over the classpath to correctly configure Liquibase to run.

Tvvsnal commented 2 years ago

Hi @nvoxland

We are trying to upgrade the Liquibase version from 3.8.0 to 4.13.0 things are working in version 3.8.0 fine when we try to upgrade to the 4.13.0 jar we are facing the below error. like unable to find liquibase home environment variable

nvoxland commented 2 years ago

@Tvvsnal it's best to use the liquibase.bat / liquibase bash script that comes with the CLI distribution. That will correctly set things up for sure.

If you are just trying to run java -jar liquibase.jar directly for some reason, you do need to set a LIQUIBASE_HOME directory that points to where liquibase should look for an internal/lib and lib directory containing jars to add to the classpath