How to execute a third party jar using maven

半世苍凉 提交于 2019-12-11 12:35:26

问题


I am using Liquibase (via its Maven plugin) to handle database migrations.

However not all Liquibase features are available via Maven. One in particular, Generate Changelog, is only available via the command line (using the downloadable liquibase.jar) with a command like this:

java -jar liquibase.jar \
--driver=oracle.jdbc.OracleDriver \
--classpath=\path\to\classes:jdbcdriver.jar \ 
--changeLogFile=com/example/db.changelog.xml \
--url="jdbc:oracle:thin:@localhost:1521:XE" \ 
--username=scott \ 
--password=tiger \ 
generateChangeLog

How can I execute this command via Maven, portably? That is, I do not want to have to add the liquibase.jar file to my project structure.

Instead, I would like to list it as a dependency (I could manually add the jar to my local repository or Nexus proxy) and then reference it when using something like the Exec Maven Plugin's exec:java or exec:exec goals, but I can't see how to do this using an executable jar with those goals. :(

Any suggestions would be much appreciated.

Thanks!


回答1:


I don't know, but may be this will help you.

Try to use maven exec plugin and put as a mainClass configuration param this: liquibase.integration.commandline.Main

I get it from MANIFEST.MF from your jar file

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
      <execution>
        ...
        <goals>
          <goal>java</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <mainClass>liquibase.integration.commandline.Main</mainClass>
      <arguments>
        <argument>--driver=oracle.jdbc.OracleDriver</argument>
        <argument>--changeLogFile=com/example/db.changelog.xml</argument>
        ...
      </arguments>
    </configuration>
  </plugin>


来源:https://stackoverflow.com/questions/16315260/how-to-execute-a-third-party-jar-using-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!