简体   繁体   中英

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. How can i do that without unzipping the zip file. I have tried to use the jarURLConnect.

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

But this gives me a

java.lang.IllegalArgumentException: Malformed \\uxxxx encoding.

There is no error if I replace "ant-contrib.jar" with a "test.properties" file.

Can anybody please help..

The property tag is for including properties, which would be in a property file. A jar file isn't a property file. 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. For example, in Subversion you'd do 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.

What I can tell you is that Java is written so that it can read files inside zips and jars without first unzipping them. 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. 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 . Then, try zipping up testing.zip and see if there's any difference. There shouldn't be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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