Maven:在构建过程中安装jar文件
我有一个要求如下。 我需要在 Maven 构建过程中运行 ant 构建文件。我需要从 pom.xml 文件调用 build.xml。我已经使用 maven-antrun-plugin 做到了这一点。现在我需要在 maven 编译我的项目源之前将 ant build 生成的 jar 文件自动安装到我的本地存储库中。我尝试使用 build-helper-maven-plugin 但没有帮助。要么我做错了,要么我没有做对。请帮忙。
更新
谢谢。 ant Maven 任务也对我有用。但是,我在构建过程结束时遇到了以下异常。非常感谢任何帮助。 org.apache.tools.ant.ExitException:未授予权限(java.lang.RuntimePermission exitVM)。在 org.apache.tools.ant.types.Permissions$MySM.checkExit(Permissions.java:196) 在 java.lang.Runtime.exit(Runtime.java:99) 在 java.lang.System.exit(System.java :275)在org.codehaus.classworlds.Launcher.main(Launcher.java:376)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)在sun。 Reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 在 java.lang.reflect.Method.invoke(Method.java:599) 在 org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)在 org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152) 在 org.apache.tools.ant.taskdefs.Java.run(Java.java:771) 在 org.apache.tools.ant .taskdefs.Java.executeJava(Java.java:221) 在 org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135) 在 org.apache.tools.ant.taskdefs.Java.execute(Java .java:108) 在 org.apache.maven.artifact.ant.Mvn.execute(Mvn.java:81) 在 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 在 sun.reflect。 NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)在java.lang.reflect.Method.invoke(Method. java:599)在org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)在org.apache.tools.ant.Task.perform(Task.java:348)在org.apache.tools .ant.Target.execute(Target.java:390) 在 org.apache.tools.ant.Target.performTasks(Target.java:411) 在 org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) )在 org.apache.tools.ant.Project.executeTarget(Project.java:1368) 在 org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 在 org.apache.tools.ant。 Project.executeTargets(Project.java:1251) 在 org.apache.tools.ant.Main.runBuild(Main.java:809) 在 org.apache.tools.ant.Main.startAnt(Main.java:217) 在 org .apache.tools.ant.launch.Launcher.run(Launcher.java:280) 位于 org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
I have got a requirement as follows.
I need to run ant build file during maven build process. I need to invoke the build.xml from my pom.xml file. I have done that using maven-antrun-plugin. Now I need to install the ant build generated jar file automatically into my local repository before maven compiles my project source. I tried using build-helper-maven-plugin but it did not help. Either I am doing something wrong, or i am not doing right. Please help.
Update
Thank you. ant maven tasks worked for me as well. However I am runing into the following exception at the end of the build process. Any help is highly appreciated.org.apache.tools.ant.ExitException: Permission (java.lang.RuntimePermission exitVM) was not granted. at org.apache.tools.ant.types.Permissions$MySM.checkExit(Permissions.java:196) at java.lang.Runtime.exit(Runtime.java:99) at java.lang.System.exit(System.java:275) at org.codehaus.classworlds.Launcher.main(Launcher.java:376) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:599) at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217) at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152) at org.apache.tools.ant.taskdefs.Java.run(Java.java:771) at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221) at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135) at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108) at org.apache.maven.artifact.ant.Mvn.execute(Mvn.java:81) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:599) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:390) at org.apache.tools.ant.Target.performTasks(Target.java:411) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) at org.apache.tools.ant.Project.executeTarget(Project.java:1368) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1251) at org.apache.tools.ant.Main.runBuild(Main.java:809) at org.apache.tools.ant.Main.startAnt(Main.java:217) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我使用 artifact:mvn 任务从 Ant 脚本中调用 Maven 时,我遇到了与上面发布的相同的异常。我设法通过将 fork="true" 添加到任务调用中来摆脱它,如下所示:
I have encountered the same exception as posted above when I was invoking Maven from within an Ant script using artifact:mvn task. I managed to get rid of it by adding the fork="true" to the task invocation as follows:
如果您的项目源需要的只是访问 ant 构建生成的内容,您可以使用 build-helper-maven-plugin 附加源。
如果需要 ant 构建的内容作为依赖项,那么您可能应该将 ant 相关代码移至单独的项目并构建它。
如果提供更多细节,也许有人可以提供更好的解决方案。
If all that your project source needs is access to the contents generated by the ant build, you can use build-helper-maven-plugin to attach the source.
If the contents of the ant build is needed as a dependency, then you should probably move the ant related code to a separate project and build it.
If more details are provided, perhaps, someone can provide a better solution.
看一下 Maven Ant 任务,它是 maven-antrun-plugin 的表兄弟。它允许从 ant 调用一些 Maven 功能,例如将 jar 安装到存储库中。它对我来说效果很好,混合构建一半是 Maven,一半是 Ant。
Take a look at Maven Ant Tasks which is the cousin of maven-antrun-plugin. It allows to invoke some Maven functionalities from ant, like installing your jar into the repository. It worked well for me with an hybrid build half Maven, half Ant.