在没有pom.xml的情况下运行mvn exec:exec

Voj*_*ěch 10 maven

我试图找到一种方法来从maven存储库中获取库并运行它.我想通过命令行定义所有内容并忽略pom.我正在努力追随:

 mvn exec:exec -Dexec.mainClass="org.main.Class" -Dspring.profiles.active=test
Run Code Online (Sandbox Code Playgroud)

当我尝试使用pom.xml运行它时,它开始获取pom中描述的所有依赖项.我真的不想要.当我在没有pom.xml的情况下运行它时,它说Goal requires a project to execute but there is no POM in this directory. Please verify you invoked Maven from the correct directory.有没有办法在没有pom的情况下运行它或者至少忽略它?

我的目标只是从没有源或罐的任何地方开始我的应用程序.

Von*_*onC 7

一种可能的解决方法是:

  • 首先拿到罐子
  • 然后执行它

为此,maven 插件dependency:get很方便,可以在没有任何 pom.xml/project 的情况下执行(所以从你想要的任何文件夹中)

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://dtp.intramundi.com/nexus/repository/maven-central/ -Dartifact=<group>:<artifact>:<version>
Run Code Online (Sandbox Code Playgroud)

将工件复制到您选择的文件夹后,像这样的插件dependency:copy-dependencies可以读取您刚刚获得的工件的 pom.xml,将所述依赖项复制到您选择的同一文件夹中。

最后, ajava -cp . yourArtifact.jar可以执行它。

我意识到这并不像“ exec:exec”那么简单,并且它从 中获取依赖项pom.xml,但至少在这里:

  • 第一步不需要任何pom.xml
  • 第二步需要pom.xml您要执行的工件的 ,并且在运行时可能需要这些依赖项:如果您想要“ exec”您的工件,则无论如何都需要这些依赖项。