简体   繁体   English

如何更新rt.jar文件?

[英]How to update rt.jar file?

I want to add some class files to rt.jar . 我想向rt.jar添加一些类文件。 How am I able to do that? 我该怎么做?

Your question indicates you have some misunderstanding of the java platform. 您的问题表明您对Java平台有一些误解。

First of all you need to know what the rt.jar is and what it does: 首先,您需要知道rt.jar是什么以及它的作用:

rt.jar is the jar that contains all the classes necessary for the java runtime. rt.jar是一个jar,其中包含Java运行时所需的所有类。 Hence it's name rt .jar 因此,它的名称为rt .jar

Now that you know that, you need to know how your java program runs: 现在您已经知道了,您需要知道Java程序如何运行:

Your java program, all your jars and classes are executed by the java virtual machine. 您的Java程序,所有的jar和类均由Java虚拟机执行。

So as you can see the code you write & the rt.jar which is used by the java run time are completely separate and should remain so. 因此,如您所见,您编写的代码与Java运行时所使用的rt.jar是完全分开的,应该保持这样。

If you need some functionality you should add it to your jar. 如果需要一些功能,则应将其添加到jar中。

Do not update it. 不要更新它。 Why do you want to update it? 为什么要更新它?

Well anyhow if you want to update it, I know one way, You can open jar file in winrar and paste updated .class files in archive. 好吧,无论如何,如果您想更新它,我知道一种方法,您可以在winrar中打开jar文件,然后将更新的.class文件粘贴到存档中。 But your jar may get in inconsistent state. 但是您的jar可能会处于不一致状态。 Do it at your own risk. 自行承担风险。

You can use this command: 您可以使用以下命令:

jar uf jar-file input-file(s)

Refer the link for details: 请参阅链接以获取详细信息:

java.sun.com/docs/books/tutorial/deployment/jar/update.html java.sun.com/docs/books/tutorial/deployment/jar/update.html

The best way to update the rt.jar is to install a newer version for Java. 更新rt.jar的最佳方法是安装Java的较新版本。 ;) ;)

If you want to add your own classes in new packages, you can add these to a jar which is in your class path. 如果要在新包中添加自己的类,可以将它们添加到类路径中的jar中。 This is preferable to changing existing classes. 这比更改现有类更好。

If the only option is to change existing classes, you can create a "patch" in a jar which you prepend to your boot class path, or you can add the jar to an lib/endorsed directory. 如果唯一的选择是更改现有类,则可以在添加到引导类路径的jar中创建“补丁”,也可以将jar添加到lib/endorsed目录中。 I wouldn't do this for production code, only for your own testing. 我不会为生产代码执行此操作,而只是为了您自己的测试。

I've tried jar.exe with the u and 0 (ie zero) options and that gets the closest to looking like the original rt.jar file but if I've updated the JDK's JRE's rt.jar I have problems with compiling and jarring after the update. 我已经尝试了使用u和0(即零)选项的jar.exe,它与原始rt.jar文件的外观最接近,但是如果我更新了JDK的JRE的rt.jar,我在编译和jarring时会遇到问题更新后。 No idea why! 不知道为什么! Simply running a program with the JRE seems to work. 仅使用JRE运行程序似乎可以工作。

I also tried -Xbootclasspath/p but couldn't get it to work. 我也尝试了-Xbootclasspath / p,但无法正常工作。

Looking at Replace a class within the Java class library with a custom version I see that there are legal problems with distributing an altered rt.jar to your customers, even if you could figure out how to do it correctly. 在查看用自定义版本替换Java类库中的类时,我发现将更改后的rt.jar分发给客户存在法律问题,即使您能弄清楚如何正确地做到这一点。 So I plan to take the advice in that page and create a java agent. 因此,我打算采纳该页面中的建议并创建一个Java代理。 That's apparently legal and works. 这显然是合法的并且可行。

One reason a person might want to modify rt.jar is to add debugging information after compiling the source that comes with the JDK with the -g option. 人们可能要修改rt.jar的一个原因是,在使用-g选项编译JDK附带的源代码之后,添加调试信息。 One may also want to patch something. 可能还需要打补丁。 These would be for one's own use, of course. 这些当然是供自己使用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM