Maven install:install-file : specified file not ex

2019-09-01 11:38发布

问题:

I tried to add custom jar into my project (to pom.xml). When I made an operation

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

I actually received an error: the specified file not exists. But the file is in the folder - that's the problem. How I can resolve this? Or how I can add custom jar without this step? I know about scope , but it's not working properly - maven variable ${basedir} cannot be used in systemPath.

Maven 3.3.9

UPDATE 1: Actually, now I find smth new: Maven doesn't like dots in groupId and version. After some tries I installed file, but it's wrong path, because instead of (e.g) org.my.local.file tree I received file in org_my_local_file folder in maven repo.

回答1:

I did this many times and it worked as expected. What do you exactly mean with :

Maven doesn't like dots in groupId and version.

What exception do you get ? You get org_my_local_file because I think you exachanged '.' in the groupId against '_' ?

You find a good tutorial here where you can see how it is done correctly :

How to include custom library into maven local repository?

EDIT : It looks like you are using windows. Especially powershell is known to cause problems. Have a look here, may be you have to escape some characters, there are some possible solutions :

install maven artifact



回答2:

I encountered this issue when trying to initialize our base development environment. We use an Ant script to initialize Maven, our developer server and other tools and includes installing a few 3rd party jars into the local Maven repository. This error, "The specified file '<path>\true' not exists" was occurring when invoking Maven from within Ant 1.9.11.

I also used this answer to specify paths identified in the Ant script and set them in the batch script template before running the batch script. Specifically, this answer offered a lot to get the batch script constructed: https://stackoverflow.com/a/36298099/2336934. Didn't take much:

    <!--  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="@\1@=" 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" />

There weren't any issues with the parameters being passed, but this must be specified correctly. Running the command you're trying to execute in a script temporarily in a command window is useful to verify the command syntax and function before trying to embed in a script.

I even created a empty true file to satisfy the error which complained the file was not a valid POM file. Filling it with basic POM content led to another error. So reader beware, this business about "true not exists" is a Red Herring.

Moving the Maven install:install-file commands out to the batch file was the key to get past the issue. It also allowed me to specify the quotes in the command as " rather than &quot; due to the commands originally being specified in the Ant script (xml).