install jar built from ant task into local maven repository

对着背影说爱祢 提交于 2020-01-05 07:25:48

问题


This is the command I want to run at the end of my Ant script:

 mvn install:install-file -Dfile=C:\dev\common\somejar.jar -DgroupId=com.myco.gt -DartifactId=somejar-Dversion=1.0.0 -Dpackaging=jar -DgeneratePOM=true

If I enter the following target at the end of my Ant script:

<target name='install_mvn_dependencies' depends='build_jars'>
    <exec executable="mvn">
        <arg value="install:install-file"/>
        <arg value="-Dfile=c:\dev\common\somejar.jar"/>
        <arg value ="-DgroupId=com.myco.gt"/>
        <arg value="-DartifactId=somejar"/>
        <arg value="-Dversion=1.2.0"/>
        <arg value="-Dpackaging=jar"/>
        <arg value="-DgeneratePOM=true"/>       
    </exec>   
</target>

I get CreateProcess error=2. The system cannot find the path specified.

even though I can run mvn on the command line. What gives?


回答1:


The mvn command is actually a batch command, so you can't execute it directly. Try this:

<exec executable="cmd.exe">
    <arg value="/c"/>
    <arg value="mvn.bat"/>
    <arg value="install:install-file"/>
    <arg value="-Dfile=c:\dev\common\somejar.jar"/>
    <arg value ="-DgroupId=com.myco.gt"/>
    <arg value="-DartifactId=somejar"/>
    <arg value="-Dversion=1.2.0"/>
    <arg value="-Dpackaging=jar"/>
    <arg value="-DgeneratePOM=true"/>       
</exec>   



回答2:


As it is ant / java, I would expect this: (untested!)

   <arg value="-Dfile=c:\\dev\\common\\somejar.jar"/>

Notice the double backslash, else it will be an escape and the path might not be found. IIRC you can also use forward slashes.

   <arg value="-Dfile=c:/dev/common/somejar.jar"/>

See also: Ant produces jsfl with backslashes instead of slashes



来源:https://stackoverflow.com/questions/13629911/install-jar-built-from-ant-task-into-local-maven-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!