I am mantaining an old java application which has dcm4che as its library. The dcm4che library is not just a jar file. It is a folder which contains jar files and other folders with some properties files and classes in different folders. I am using WindowsXP and java 1.6.
我正在维护一个以dcm4che为库的旧java应用程序。 dcm4che库不仅仅是一个jar文件。它是一个文件夹,其中包含jar文件和其他文件夹,其中包含一些属性文件和不同文件夹中的类。我正在使用WindowsXP和java 1.6。
When we run our application, we need to put those folders, jar files into the classpath by doing something like these:
当我们运行我们的应用程序时,我们需要通过执行以下操作将这些文件夹,jar文件放入类路径中:
set CLASSPATH=.;%PROJ_HOME%\classes;^
%THIRDPARTY_HOME%\dcm4che;^
%THIRDPARTY_HOME%\dcm4che\classes;^
%THIRDPARTY_HOME%\dcm4che\resources;^
Now I try to put all of them into one jar file to simplify the sources control. So I create a manifest.txt file with the following content:
现在我尝试将所有这些放入一个jar文件中以简化源代码控制。所以我创建了一个manifest.txt文件,其中包含以下内容:
Class-Path: classes;resources;lib\dcm4che.jar;getopt.jar
Then I create a dcm4che.jar by running jar:
然后我通过运行jar创建一个dcm4che.jar:
jar -cfm dcm4che.jar manifest.txt *
A dcm4che.jar is created. The I verify the result by extracting all contents and check the manifest file and my classpath is there:
创建了一个dcm4che.jar。我通过提取所有内容并检查清单文件验证结果,我的类路径在那里:
Manifest-Version: 1.0
Class-Path: classes;resources;lib\dcm4che.jar;getopt.jar
Created-By: 1.6.0_25 (Sun Microsystems Inc.)
Then I modify the application classpath to point to the new generated dcm4che.jar and delete those older entries.
然后我修改应用程序类路径以指向新生成的dcm4che.jar并删除那些旧条目。
When I run it, I get NoClassDefFoundError. But that class is under the classes folder inside the new created jar file.
当我运行它时,我得到NoClassDefFoundError。但是该类位于新创建的jar文件中的classes文件夹下。
I am missing anything?
我错过了什么?
3 个解决方案
#1
0
Java does not support jars in jars. So, the easiest way is to expand this file and add all it content to classpath. I think you can easily do this using script. You anyway have script that runs your application, right? So add several lines that expand this file to temporary or user home directory.
Java不支持jar中的jar。因此,最简单的方法是扩展此文件并将其全部内容添加到类路径中。我认为您可以使用脚本轻松完成此操作。你还有运行你的应用程序的脚本,对吧?因此,添加几行将此文件扩展到临时或用户主目录。
If you do not want to do this or it is forbidden for other reasons you have to implement your own classloader that loads cliesses from nested jar. It is not so hard to do but it requires some efforts. You can use VFS from Jakarta. It will simplify implementation.
如果您不想这样做或者由于其他原因而被禁止,您必须实现自己的类加载器,从嵌套jar加载cliesses。这不是很难,但需要一些努力。您可以使用雅加达的VFS。它将简化实施。
But I'd recommend you the first way.
但我建议你第一种方式。
#2
0
You could use ONE-JAR to package the class files and jar files into your final executable.
您可以使用ONE-JAR将类文件和jar文件打包到最终的可执行文件中。
#3
0
A jar file is essentially a zip file.
jar文件本质上是一个zip文件。
There are various utilities which allow you to mount zip files as a read-only drive or dvd.
有各种实用程序,允许您将zip文件作为只读驱动器或DVD安装。
Similarly, there are utilities that mount iso images as a cd or dvd. I am addicted to them because they are very helpful. Especially when a piece of software insists on reading its DVD and I have a few of such software which I wish to run concurrently and I have only one DVD/CD drive.
同样,有些实用程序可以将iso映像挂载为cd或dvd。我沉迷于他们,因为他们非常有帮助。特别是当一个软件坚持阅读它的DVD时,我有一些这样的软件,我希望同时运行,我只有一个DVD / CD驱动器。
Once mounted as a ROM drive, hmm ... needless to say any further.
一旦作为ROM驱动器安装,嗯......不用再说了。
#1
0
Java does not support jars in jars. So, the easiest way is to expand this file and add all it content to classpath. I think you can easily do this using script. You anyway have script that runs your application, right? So add several lines that expand this file to temporary or user home directory.
Java不支持jar中的jar。因此,最简单的方法是扩展此文件并将其全部内容添加到类路径中。我认为您可以使用脚本轻松完成此操作。你还有运行你的应用程序的脚本,对吧?因此,添加几行将此文件扩展到临时或用户主目录。
If you do not want to do this or it is forbidden for other reasons you have to implement your own classloader that loads cliesses from nested jar. It is not so hard to do but it requires some efforts. You can use VFS from Jakarta. It will simplify implementation.
如果您不想这样做或者由于其他原因而被禁止,您必须实现自己的类加载器,从嵌套jar加载cliesses。这不是很难,但需要一些努力。您可以使用雅加达的VFS。它将简化实施。
But I'd recommend you the first way.
但我建议你第一种方式。
#2
0
You could use ONE-JAR to package the class files and jar files into your final executable.
您可以使用ONE-JAR将类文件和jar文件打包到最终的可执行文件中。
#3
0
A jar file is essentially a zip file.
jar文件本质上是一个zip文件。
There are various utilities which allow you to mount zip files as a read-only drive or dvd.
有各种实用程序,允许您将zip文件作为只读驱动器或DVD安装。
Similarly, there are utilities that mount iso images as a cd or dvd. I am addicted to them because they are very helpful. Especially when a piece of software insists on reading its DVD and I have a few of such software which I wish to run concurrently and I have only one DVD/CD drive.
同样,有些实用程序可以将iso映像挂载为cd或dvd。我沉迷于他们,因为他们非常有帮助。特别是当一个软件坚持阅读它的DVD时,我有一些这样的软件,我希望同时运行,我只有一个DVD / CD驱动器。
Once mounted as a ROM drive, hmm ... needless to say any further.
一旦作为ROM驱动器安装,嗯......不用再说了。