Maven install:install-文件:指定的文件不存在

Maven install:install-file : specified file not exists

我试图将自定义 jar 添加到我的项目中(到 pom.xml)。当我进行操作时

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<myGroup> -DartifactId=<myArtifactId> -Dversion=<myVersion> -Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>

我实际上收到一个错误:指定的文件不存在。但文件在文件夹中 - 这就是问题所在。我该如何解决这个问题?或者我如何在没有这一步的情况下添加自定义 jar?我知道 scope ,但它不能正常工作 - maven 变量 ${basedir} 不能在 systemPath 中使用。

行家 3.3.9

更新 1:实际上,现在我发现了一些新东西:Maven 不喜欢 groupId 和版本中的点。经过一些尝试我安装了文件,但它是错误的路径,因为我收到的文件不是(例如)org.my.local.file 树,而是在 Maven 仓库的 org_my_local_file 文件夹中。

我这样做了很多次并且按预期工作。 你到底是什么意思:

Maven doesn't like dots in groupId and version.

你得到了什么异常? 你得到 org_my_local_file 因为我认为你交换了 '.'在针对“_”的 groupId 中?

你在这里找到了一个很好的教程,在那里你可以看到它是如何正确完成的:

How to include custom library into maven local repository?

编辑: 看起来您正在使用 windows。众所周知,powershell 会引起问题。看看这里,可能你必须转义一些字符,有一些可能的解决方案:

install maven artifact

我在尝试初始化我们的基础开发环境时遇到了这个问题。我们使用 Ant 脚本来初始化 Maven、我们的开发人员服务器和其他工具,并包括将一些第 3 方 jar 安装到本地 Maven 存储库中。从 Ant 1.9.11 中调用 Maven 时发生此错误 "The specified file '<path>\true' not exists"。

我还使用此答案指定 Ant 脚本中标识的路径,并在 运行 批处理脚本之前的批处理脚本模板中设置它们。 具体来说,这个答案为构建批处理脚本提供了很多帮助:。没用多少:

    <!--  generate the batch file -->
    <tempfile property="temp.file" suffix=".properties" deleteonexit="true" destdir="${env.TEMP}" />
    <echoproperties destfile="${temp.file}" />
    <replaceregexp file="${temp.file}" match="([^=]*)=" replace="@@=" byline="true" />
    <copy file="${basedir}/scripts/install-jars.template" tofile="${basedir}/scripts/install-jars.bat" />
    <replace file="${basedir}/scripts/install-jars.bat" replacefilterfile="${temp.file}" />

    <echo message="Running batch file for Maven setup" />
    <exec executable="${basedir}/scripts/install-jars.bat" />
    <delete file="${basedir}/scripts/install-jars.bat" deleteonexit="true" />

传递的参数没有任何问题,但必须正确指定。 运行 您尝试在命令 window 中临时在脚本中执行的命令对于在尝试嵌入脚本之前验证命令语法和功能很有用。

我什至创建了一个空的 true 文件来解决抱怨该文件不是有效 POM 文件的错误。用基本的 POM 内容填充它会导致另一个错误。所以 reader 小心,这个关于 "true not exists" 的生意是红鲱鱼。

将 Maven install:install-file 命令移到批处理文件中是解决问题的关键。它还允许我将命令中的引号指定为 " 而不是 &quot;,因为命令最初是在 Ant 脚本中指定的 (xml)。