Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 调用M2存储库中的jar文件_Maven - Fatal编程技术网

Maven 调用M2存储库中的jar文件

Maven 调用M2存储库中的jar文件,maven,Maven,我有一个项目,我想在当前项目的后期执行阶段调用M2 repo中的另一个Jar文件 我的POM的骨骼样本 org.codehaus.mojo execmaven插件 1.1 执行一 验证 可执行文件>java -罐子 JarToInvoke.jar /C:/repo的路径 执行官 JarToInvoke的组ID 贾托因沃克 1.0.0-SNAPSHOT 我尝试使用maven exec插件,但存在以下问题: 我需要在哪里指定JarToInvoke依赖项?作为项目依赖项还是作为exec插件依赖项

我有一个项目,我想在当前项目的后期执行阶段调用M2 repo中的另一个Jar文件

我的POM的骨骼样本


org.codehaus.mojo
execmaven插件
1.1
执行一
验证
可执行文件>java
-罐子
JarToInvoke.jar
/C:/repo的路径
执行官
JarToInvoke的组ID
贾托因沃克
1.0.0-SNAPSHOT
我尝试使用maven exec插件,但存在以下问题:

  • 我需要在哪里指定JarToInvoke依赖项?作为项目依赖项还是作为exec插件依赖项

  • 通过对工作目录(/C:/repo路径)进行硬编码,我能够调用JarToInvoke工件。但这不是一个好的解决方案,因为最终这个项目应该运行在任何具有不同操作系统的m/c中。那么,如何让exec插件在项目的M2 repo中搜索JarToInvoke工件(默认类路径)

  • 3.在工作目录中硬编码M2 repo路径时,我能够调用JarToInvoke工件。但是,在运行JarToInvoke工件时,它引发了另一个依赖性问题,JarToInvoke的一些log4j依赖性无法找到。我把这个罐子做成了一个有阴影的罐子,它的效果和预期的一样。但这不是一个永久或好的解决方案(因为着色jar大小为35mb)。如何指示exec插件在M2 repo中查找依赖jar

    请分享你的建议。提前感谢。

    我认为,这是Exec插件文档中描述的内容

    如果您可以使用
    exec:java
    目标而不是
    exec:exec
    ,那么查找JVM将为您提供帮助。您还可以通过更改插件的
    includeProjectDependencies
    includePluginDependencies
    配置选项来引入插件依赖项或项目依赖项

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
    
        <executions>
            <execution>
                <id>exec-one</id>
                <phase>verify</phase>
                <configuration>
                    <includeProjectDependencies>false</includeProjectDependencies>
                    <includePluginDependencies>true</includePluginDependencies>
                    <executableDependency>
                        <groupId>GroupId of JarToInvoke</groupId>
                        <artifactId>JarToInvoke</artifactId>
                    </executableDependency>
    
                    <!-- Look up the main class from the manifest inside your dependency's JAR -->
                    <mainClass>com.example.Main</mainClass>
                    <arguments>
                        <!-- Add any arguments after your JAR here --->
                    </arguments>
                </configuration>
                <goals>
                  <goal>java</goal>
               </goals>
            </execution>
        </executions>
    
        <dependencies>
            <dependency>
                <groupId>GroupId of JarToInvoke</groupId>
                <artifactId>JarToInvoke</artifactId>
                <version>1.0.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </plugin>    
    
    
    org.codehaus.mojo
    
    目标是将依赖项从本地存储库复制到预定义位置(例如
    ${project.build.directory}
    /exec jars)然后,您可以在exec插件的
    工作目录
    配置选项中输入该目录。

    找到jar文件绝对路径的更简单方法可能是使用
    maven dependency plugin
    属性
    目标

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>properties</goal>
            </goals>
          </execution>
        </executions>
    </plugin>
    <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>1.1</version>
    
            <executions>
              <execution>
              <id>exec-one</id>
              <phase>verify</phase>
              <configuration>
                  <executable>java</executable>
                  <arguments> 
                       <argument>-jar</argument>
                       <argument>${GroupIdofJarToInvoke:JarToInvoke:jar}</argument>
                  </arguments>                
                  <workingDirectory>/C:/path to repo</workingDirectory>
                  </configuration>
                      <goals>
                          <goal>exec</goal>
                      </goals>
                  </execution>
                </executions>
            </plugin>    
          </plugins>
    
          <dependencies>
               <dependency>
                   <groupId>GroupIdofJarToInvoke</groupId>
                   <artifactId>JarToInvoke</artifactId>
                   <version>1.0.0-SNAPSHOT</version>
               </dependency>
          <dependencies>
    
    
    org.apache.maven.plugins
    maven依赖插件
    2.3
    性质
    org.codehaus.mojo
    execmaven插件
    1.1
    执行一
    验证
    JAVA
    -罐子
    ${GroupIdofJarToInvoke:JarToInvoke:jar}
    /C:/repo的路径
    执行官
    GroupIdofJarToInvoke
    贾托因沃克
    1.0.0-SNAPSHOT
    
    感谢prunge提供的宝贵信息。但是在如上所述配置POM之后,它将抛出以下异常;'sun.reflect.reflect.InvocationTargetException位于sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)位于sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)位于java.lang.reflect.Method.java:597在org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)和java.lang.Thread.run(Thread.java:662)“@RahulR.Prasad上,它看起来像是asm库的一个不同版本,与JarToInvoke在执行JAR时所期望的版本不同。尝试显式地为类所需的asm版本的exec插件添加依赖项,
    com.tvworks.testing.tools
    感谢Prunge,我能够使用maven依赖项插件的“复制依赖项”目标将依赖项复制到“${project.build.directory}/exec jars”。此外,我还使用maven exec插件调用了execjar目录中复制的jar。谢谢你指导我。
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>properties</goal>
            </goals>
          </execution>
        </executions>
    </plugin>
    <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>1.1</version>
    
            <executions>
              <execution>
              <id>exec-one</id>
              <phase>verify</phase>
              <configuration>
                  <executable>java</executable>
                  <arguments> 
                       <argument>-jar</argument>
                       <argument>${GroupIdofJarToInvoke:JarToInvoke:jar}</argument>
                  </arguments>                
                  <workingDirectory>/C:/path to repo</workingDirectory>
                  </configuration>
                      <goals>
                          <goal>exec</goal>
                      </goals>
                  </execution>
                </executions>
            </plugin>    
          </plugins>
    
          <dependencies>
               <dependency>
                   <groupId>GroupIdofJarToInvoke</groupId>
                   <artifactId>JarToInvoke</artifactId>
                   <version>1.0.0-SNAPSHOT</version>
               </dependency>
          <dependencies>