[英]Adding the current directory to a JAR file's classpath
My code is being deployed as a JAR file. 我的代码被部署为JAR文件。 The JAR contains a directory lib
which contains a number of third-party JARs which my code requires. JAR包含目录lib
,该目录包含我的代码所需的许多第三方JAR。 I've added these to the classpath
, using Ant, via the MANIFEST.MF
. 我已通过MANIFEST.MF
使用Ant将它们添加到classpath
。
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. 在JAR的根目录中还有一个queries.properties
文件。
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. 我希望它们与JAR文件位于同一目录中,并让代码能够找到它们。 I believe for the code to be able to locate these properties files, they need to be in the classpath
. 我相信要使代码能够找到这些属性文件,它们必须位于classpath
。 I therefore need to add the JAR file's directory to the classpath
. 因此,我需要将JAR文件的目录添加到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
? 如果正确,那么如何使用Ant将JAR的当前目录添加到MANIFEST.MF
的类路径中? I added the JARs in the lib
directory to the classpath
using the manifestclasspath
Ant task. 我使用manifestclasspath
任务将lib
目录中的JAR添加到了classpath
。
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 另请参阅可执行jar无法找到属性文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.