Maven 调用M2存储库中的jar文件
我有一个项目,我想在当前项目的后期执行阶段调用M2 repo中的另一个Jar文件 我的POM的骨骼样本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插件依赖项
org.codehaus.mojo
execmaven插件
1.1
执行一
验证
可执行文件>java
-罐子
JarToInvoke.jar
/C:/repo的路径
执行官
JarToInvoke的组ID
贾托因沃克
1.0.0-SNAPSHOT
我尝试使用maven 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>