在没有pom.xml的情况下运行mvn exec:exec [英] Run mvn exec:exec without a pom.xml

查看:168
本文介绍了在没有pom.xml的情况下运行mvn exec:exec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法,仅从maven存储库中获取一个库并运行它.我想通过命令行定义所有内容,而忽略pom.我正在尝试关注:

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:

 mvn exec:exec -Dexec.mainClass="org.main.Class" -Dspring.profiles.active=test

当我尝试使用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的情况下运行它,或者至少忽略它?

When I try to run it with pom.xml, it starts to fetch all the dependencies described in the pom. Which I really don't want. When I run it without the pom.xml, it says Goal requires a project to execute but there is no POM in this directory. Please verify you invoked Maven from the correct directory. Is there a way to run it without the pom or at least ignore it?

我的目标只是从没有源代码或jar的任何地方启动我的应用程序.

My goal is just to start my application from anywhere without sources or jars.

推荐答案

一种可能的解决方法是:

One possible workaround would be to:

  • 先拿罐子
  • 然后执行它

为此, maven插件dependency:get 方便,并且无需任何pom.xml/project即可执行(因此可从任何所需的文件夹中执行)

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=<group>:<artifact>:<version>

将工件复制到您选择的文件夹后,将使用

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.

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

我意识到这不只是"exec:exec"那么简单,而且它从pom.xml获取依赖项,但至少在这里:

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

  • 第一步不需要任何pom.xml
  • 第二步需要您要执行的工件的pom.xml,并且在运行时可能需要这些依赖项:如果您要"exec"工件,则仍然需要这些依赖项.
  • 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.

这篇关于在没有pom.xml的情况下运行mvn exec:exec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆