简体   繁体   English

Ant-从zip文件中导入jar

[英]Ant - Import jar from within a zip file

I want to include a jar file ( ant-contrib.jar ) in my ant build.xml from within a zip. 我想从一个zip文件中在我的ant build.xml中包含一个jar文件( ant-contrib.jar )。 How can i do that without unzipping the zip file. 我该如何做而不解压缩zip文件。 I have tried to use the jarURLConnect. 我试图使用jarURLConnect。

<property url="jar:file:/D:/testing.zip!/testing/ant-contrib.jar" />

But this gives me a 但这给了我一个

java.lang.IllegalArgumentException: Malformed \\uxxxx encoding. java.lang.IllegalArgumentException:\\ uxxxx编码格式错误。

There is no error if I replace "ant-contrib.jar" with a "test.properties" file. 如果将“ ant-contrib.jar”替换为“ test.properties”文件,则没有错误。

Can anybody please help.. 有人可以帮忙吗..

The property tag is for including properties, which would be in a property file. property标签用于包括属性文件中的属性。 A jar file isn't a property file. jar文件不是属性文件。 The property docs are pretty clear. 属性文档非常清楚。

You need to unzip the file in order to add it to a classpath, and then actually add it to a classpath: see the path-like structures documentation. 您需要解压缩文件才能将其添加到类路径,然后将其实际添加到类路径:请参见类路径结构文档。 It's not just a property, though. 不过,这不仅仅是财产。

选中解压缩任务

尝试使用“ zip”而不是“ jar”:

<property url="zip:file:/D:/testing.zip!/testing/ant-contrib.jar" />

Not entirely sure what you're doing, but URLs always have two forward slashes as a delimiter. 不能完全确定您在做什么,但是URL始终以两个斜杠作为分隔符。 For example, in Subversion you'd do file://D:/testing.zip!/testing/ant-contrib.jar . 例如,在Subversion中,您将执行file://D:/testing.zip!/testing/ant-contrib.jar

Now a URL spec in a <property> task should point to a javaspec'd property file , so I don't think a jar will work. 现在, <property>任务中的URL规范应指向javaspec的属性文件 ,因此我认为jar无效。

What I can tell you is that Java is written so that it can read files inside zips and jars without first unzipping them. 我可以告诉您的是,编写Java是为了使它可以读取zip和jar中的文件而无需先将它们解压缩。 There should be no difference in Java if you unzipped testing.zip into a directory called testing.zip and accessed files from there, or kept it as a zipfile. 如果将testing.zip压缩到一个名为testing.zip的目录中并从那里访问文件,或者将其保存为zipfile,则Java中应该没有任何区别。 You should be able to include it in the path name (sans exclamation point): 您应该可以将其包括在路径名中(没有感叹号):

<path id="classpath>
    <pathelement path="D:/testing.zip/testing/ant-contrib.jar"/>
    <yadda, yadda, yadda/>
</path>

That should work. 那应该工作。

What you can try is to unzip testing.zip into a directory of the same name, and see if you can access the files in ant-contrib.jar . 您可以尝试将testing.zip解压缩到同名目录中,然后查看是否可以访问ant-contrib.jar的文件。 Then, try zipping up testing.zip and see if there's any difference. 然后,尝试压缩testing.zip,看看是否有任何区别。 There shouldn't be. 应该没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM