格罗维+ Antbuilder:如何将 Grape 与 taskdef 一起使用?
这与 .我正在尝试使用 Grape 动态添加 maven-ant-tasks jar,模拟以下内容:
<taskdef uri="antlib:org.apache.maven.artifact.ant"
resource="org/apache/maven/artifact/ant/antlib.xml"
classpathref="ant.classpath" />
我尝试使用 Grape.grab() 使 maven-ant-tasks 可用于 AntBuilder,如下所示:
import groovy.grape.Grape
println "grab..."
Grape.grab(group:'ant', module:'ant', version:'1.7.0', classLoader:this.class.classLoader.rootLoader)
Grape.grab(group: 'org.apache.maven', module: 'maven-ant-tasks', version: '2.0.9')
println "ant taskdef..."
def ant = new AntBuilder()
ant.taskdef (resource: "org/apache/maven/artifact/ant/antlib.xml" )
但这不起作用因为 Grape 将模块添加到与 ANT 引擎使用的类加载器不同的类加载器中。因此,我采纳了 这个 AntBuilder 类路径问题 的建议并制作了 Grape使用根类加载器:
import groovy.grape.Grape
println "grab..."
Grape.grab(group:'ant', module:'ant', version:'1.7.0', classLoader:this.class.classLoader.rootLoader)
Grape.grab(group: 'org.apache.maven', module: 'maven-ant-tasks', version: '2.0.9', classLoader: this.class.classLoader.rootLoader)
println "ant taskdef..."
def ant = new AntBuilder()
ant.taskdef (resource: "org/apache/maven/artifact/ant/antlib.xml" )
现在它会抛出 LinkageError:
Caught: : java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Locator used in the signature
at test.mavenanttasks.run(mavenanttasks.groovy:11)
有关使其正常工作的任何提示吗?或者,整个事情是个坏主意吗?
This is related to . I'm trying to dynamically add the maven-ant-tasks jars with Grape, simulating this:
<taskdef uri="antlib:org.apache.maven.artifact.ant"
resource="org/apache/maven/artifact/ant/antlib.xml"
classpathref="ant.classpath" />
I've tried to use Grape.grab() to make maven-ant-tasks available to AntBuilder like this:
import groovy.grape.Grape
println "grab..."
Grape.grab(group:'ant', module:'ant', version:'1.7.0', classLoader:this.class.classLoader.rootLoader)
Grape.grab(group: 'org.apache.maven', module: 'maven-ant-tasks', version: '2.0.9')
println "ant taskdef..."
def ant = new AntBuilder()
ant.taskdef (resource: "org/apache/maven/artifact/ant/antlib.xml" )
but that doesn't work because Grape adds the modules to a different ClassLoader from the one that ANT engine is using. So, I took the advice from this AntBuilder classpath question and made Grape use the root ClassLoader:
import groovy.grape.Grape
println "grab..."
Grape.grab(group:'ant', module:'ant', version:'1.7.0', classLoader:this.class.classLoader.rootLoader)
Grape.grab(group: 'org.apache.maven', module: 'maven-ant-tasks', version: '2.0.9', classLoader: this.class.classLoader.rootLoader)
println "ant taskdef..."
def ant = new AntBuilder()
ant.taskdef (resource: "org/apache/maven/artifact/ant/antlib.xml" )
Now it throws a LinkageError:
Caught: : java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Locator used in the signature
at test.mavenanttasks.run(mavenanttasks.groovy:11)
Any hints on getting this to work? Or, is the whole thing a bad idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了这个: http://groovy.codehaus.org/Using+Ant+ Libraries+with+AntBuilder
首先,将 maven-ant-tasks 放入根类加载器中:
或者,对于旧版本的 Groovy:
Maven ANT 任务是一个“AntLib”,可以像这样加载它们:
I found this: http://groovy.codehaus.org/Using+Ant+Libraries+with+AntBuilder
First, put maven-ant-tasks in the root classloader with:
Alternatively, for older versions of Groovy:
The Maven ANT tasks are an 'AntLib', and they can be loaded like this:
我们可以使用 java.net.URLClassLoader 或其子类创建 ant 路径(类路径)
例如:
We can create ant path(classpath) using java.net.URLClassLoader or it's subclass
eg: