重新打包 .jar 文件 [英] Repackaging the .jar file

查看:26
本文介绍了重新打包 .jar 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 JRE7 库中的一些 jar 添加到我的 Android 项目中.但是例如 rt.jar 与 Adroid 2.2 SDK 中的 android.jar 冲突,所以我得到这个错误:

I need to add some jars from JRE7 library to my Android project. But for example rt.jar is in conflict with android.jar from Adroid 2.2 SDK, so I get this error:

不明智或错误地使用核心类(java.* 或 javax.*)不构建核心库时.

Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.

这通常是由于无意中包含了一个核心库文件在应用程序的项目中,当使用 IDE(例如蚀).如果你确定你不是故意定义一个核心课程,那么这是最有可能的解释继续.

This is often due to inadvertently including a core library file in your application's project, when using an IDE (such as Eclipse). If you are sure you're not intentionally defining a core class, then this is the most likely explanation of what's going on.

但是,您实际上可能正在尝试在核心中定义一个类命名空间,例如您可能采用的来源,来自非 Android 虚拟机项目.这将最肯定不行.至少,它会危害您的应用程序与平台未来版本的兼容性.它的合法性也常常有问题.

However, you might actually be trying to define a class in a core namespace, the source of which you may have taken, for example, from a non-Android virtual machine project. This will most assuredly not work. At a minimum, it jeopardizes the compatibility of your app with future versions of the platform. It is also often of questionable legality.

如果你真的打算构建一个核心库——这只是适合作为创建完整虚拟机的一部分分发,而不是编译应用程序——然后使用--core-library"选项来抑制此错误消息.

If you really intend to build a core library -- which is only appropriate as part of creating a full virtual machine distribution, as opposed to compiling an application -- then use the "--core-library" option to suppress this error message.

如果您继续使用--core-library"但实际上构建应用程序,然后预先警告您的应用程序在某些时候仍然无法构建或运行.请成为为愤怒的客户做好准备,例如,他们发现您的一旦升级其操作,应用程序将停止运行系统.你要为这个问题负责.

If you go ahead and use "--core-library" but are in fact building an application, then be forewarned that your application will still fail to build or run, at some point. Please be prepared for angry customers who find, for example, that your application ceases to function once they upgrade their operating system. You will be to blame for this problem.

如果您合法地使用某些恰好在核心包,那么您拥有的最简单的安全替代方案是重新打包该代码.也就是说,将有问题的类移动到你自己的包命名空间.这意味着他们永远不会在与核心系统类冲突.JarJar 是一个可能有帮助的工具你在这方面的努力.如果你发现你不能这样做,那么这表明你所走的道路最终会导致痛苦、痛苦、悲伤和哀叹.

If you are legitimately using some code that happens to be in a core package, then the easiest safe alternative you have is to repackage that code. That is, move the classes in question into your own package namespace. This means that they will never be in conflict with core system classes. JarJar is a tool that may help you in this endeavor. If you find that you cannot do this, then that is an indication that the path you are on will ultimately lead to pain, suffering, grief, and lamentation.

我知道关于它的话题有很多,比如 JarJarOneJarFatJar 可能对我有好处.但是我不知道如何使它们中的任何一个工作并且文档并没有真正清楚(对我而言).我猜他们使用 Ant 命令,但我一直使用 Eclipse 内置构建器,现在我不知道如何使用 Ant 或上述任何一个.

I know there have been several threads about it and things like JarJar, OneJar or FatJar might be good for me. But I don't know how to make any of them work and documentation doesn't really make it clear (for me). I guess they use Ant commands, but I have always used Eclipse built-in builder and now I have no idea how to use neither Ant nor any of mentioned above.

所以我的问题是:如何重新打包这个 rt.jar 以便我可以在我的 Android 项目中编译它?

So my question is: how can I repack this rt.jar so I could compile it in my Android project?

谢谢!

好的,所以我想要实现的是创建一个 .jar,它可以在开发 Android 应用程序期间使用(简化一些功能,并不重要).但我也希望能够将相同的 .jar 添加到标准 Java 项目中,以便在那里也使用一些功能.它看起来像这样:编写应用程序的人将此 .jar 添加到他的 Java 项目中 -> 它使他能够生成某些文件(需要互联网来完成) -> 然后将这些生成的文件添加到 Android 项目中 -> 稍后,当有人使用此 Android 时应用程序,这些文件在不使用互联网(离线)的情况下提供某些功能.

Ok, so what I want to achieve is to create a .jar, which can be used during developing Android application (simplifies some functionalities, doesn't really matter). But I would also like to be able to add the very same .jar to standard Java project in order to use some functions there as well. It would look like this: Whoever writes an application adds this .jar to his Java project -> it enables him to generate certain files (internet is needed to do it) -> these generated files are then added to Android project -> later on, when somebody uses this Android app, these files provide certain functionalities without using internet (off-line).

推荐答案

在任何项目中这样做都是不明智的,即使可能.您将面临大量的类不兼容和加载问题.但在任何情况下,这都无关紧要,因为核心 Java 库在您的档案被触及之前就已加载,因此任何此类覆盖它们的尝试都没有实际意义.

It would be ill-advised to do this in any project at all, even if it were possible. You would be opening yourself to a wealth of class incompatibility and loading problems. But in any case it doesn't even matter because the core Java libraries are loaded way before your archives are even touched, making any such attempt at overriding them moot.

更不用说 Android 正在使用自己的 JVM 实现,该实现与 JDK 6 不完全兼容(忘记 JDK 7).另请注意,将核心 Java 库与您的代码一起打包可能会侵犯版权,并且可能会更改您的许可选项 (IANAL).

Not to even talk about the fact that Android is using its own JVM implementation which is not fully compatible with JDK 6 (forget JDK 7). Also note that it may be a copyright violation to package the core Java libraries with your code and could change your licensing options (IANAL).

您需要找到另一种方法来解决您遇到的任何问题(您在问题中未提及).

You need to find another way to resolve whatever issue you are having (which you failed to mention in your question).

这篇关于重新打包 .jar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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