Run mvn exec:exec without a pom.xml

后端 未结 2 1794
梦毁少年i
梦毁少年i 2021-02-19 15:58

I am trying to find a way just to fetch a library from maven repository and run it. I want to define everything by command line and ignore the pom. I am trying following:

<
2条回答
  •  爱一瞬间的悲伤
    2021-02-19 16:53

    One possible workaround would be to:

    • first get the jar
    • then execute it

    For that, the maven plugin dependency:get is handy, and can be executed without any pom.xml/project (so from any folder you want)

    mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://dtp.intramundi.com/nexus/repository/maven-central/ -Dartifact=::
    

    Once you have copied the artifact to the folder of your choice, a plugin like dependency:copy-dependencies could, reading the pom.xml of the artifact you just got, copy said dependencies to the same folder of your choice.

    Finally, a java -cp . yourArtifact.jar can execute it.

    I realize this is not as straightforward as just "exec:exec", and that it fetches dependencies from the pom.xml, but here at least:

    • the first step does not require any pom.xml,
    • the second step needs the pom.xml of the very artifact you want to execute, and those dependencies might be needed at runtime: you would need those anyway if you want to 'exec' your artifact.

提交回复
热议问题