罐子里面的参考罐子 [英] Reference jars inside a jar

查看:117
本文介绍了罐子里面的参考罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jar,其内容如下所示:

I have a jar whose content looks as shown below,

以下是我的清单文件

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.7.0_06-b24 (Oracle Corporation)
Main-Class: org.sai.com.DerbyDemo
Class-Path: derby.jar derbyclient.jar derbynet.jar derbytools.jar



<当我尝试运行jar时,它抛出了一个 ClassNotFoundExcception ,这意味着它没有引用外部jar中的jar。

When i try to run the jar, it has thrown a ClassNotFoundExcception meaning it isn't referencing the jars inside the outer jar.

Class-Path 属性中,如何引用jar( derby.jar 等) )在实际的jar里面?

In the Class-Path attribute, how can I reference jars (derby.jar, etc) inside the actual jar?

推荐答案

你需要一个自定义的类加载器,看看一个罐子

You will need a custom class loader for this, have a look at One Jar.


One-JAR允许您将Java应用程序及其依赖项Jars打包到一个可执行的Jar文件中。

One-JAR lets you package a Java application together with its dependency Jars into a single executable Jar file.

它有一个ant任务,可以简化它的构建。

It has an ant task which can simplify the building of it as well.

参考(来自背景


大多数开发人员合理地假设将依赖Jar文件放入他们自己的Jar文件中,并向META-INF添加Class-Path属性/ MANIFEST将发挥作用




jarname.jar
| /META-INF
| |  MANIFEST.MF
| |    Main-Class: com.mydomain.mypackage.Main
| |    Class-Path: commons-logging.jar
| /com/mydomain/mypackage
| |  Main.class
| commons-logging.jar




不幸的是这是不起作用 。 Java Launcher $ AppClassLoader 不知道如何使用这种 Class-Path 。试图使用 jar:file:jarname.jar!/commons-logging.jar 也导致死胡同。只有将支持的Jar文件安装(即分散)到安装jarname.jar文件的目录中时,此方法才有效。

Unfortunately this is does not work. The Java Launcher$AppClassLoader does not know how to load classes from a Jar inside a Jar with this kind of Class-Path. Trying to use jar:file:jarname.jar!/commons-logging.jar also leads down a dead-end. This approach will only work if you install (i.e. scatter) the supporting Jar files into the directory where the jarname.jar file is installed.

这篇关于罐子里面的参考罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆