简体   繁体   中英

Adding the current directory to a JAR file's classpath

My code is being deployed as a JAR file. The JAR contains a directory lib which contains a number of third-party JARs which my code requires. I've added these to the classpath , using Ant, via the MANIFEST.MF .

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 20.5-b03 (Sun Microsystems Inc.)
Main-Class: com.package.Class
Class-Path: ../lib/c3p0-0.9.1.2.jar ../lib/dbunit-2.4.8.jar ../lib/gua
va-10.0.1.jar ../lib/hsqldb.jar ../lib/javax.jms.jar ../lib/log4j-1.2
 .16.jar ../lib/mockito-all-1.9.0.jar ../lib/ojdbc14.jar ../lib/slf4j-
 api-1.6.4.jar ../lib/slf4j-log4j12-1.6.4.jar ../lib/xmlunit-1.3.jar

There is also a queries.properties file which is in the root of the JAR.

There are two further properties files which are required. I would like these to reside in the same directory as the JAR file and for the code to be able to locate them. I believe for the code to be able to locate these properties files, they need to be in the classpath . I therefore need to add the JAR file's directory to the classpath .

Firstly, is this the correct approach of should I use an alternative means of locating the properties files?

If this is correct, how do I use Ant to add the JAR's current directory to the classpath in MANIFEST.MF ? I added the JARs in the lib directory to the classpath using the manifestclasspath Ant task.

Have you tried adding the . as a reference to the current directory?

   <jar jarfile="dummy.jar">
            <manifest>
                    <attribute name="Main-Class" value="com.package.Class"/>
                    <attribute name="Class-Path" value=". ${jar.class.path}"/>
            </manifest>               
    </jar>

Please also see Executable jar won't find the properties files

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