How to update rt.jar file?

[亡魂溺海] 提交于 2019-12-24 20:21:52

问题


I want to add some class files to rt.jar. How am I able to do that?


回答1:


Your question indicates you have some misunderstanding of the java platform.

First of all you need to know what the rt.jar is and what it does:

rt.jar is the jar that contains all the classes necessary for the java runtime. Hence it's name rt.jar

Now that you know that, you need to know how your java program runs:

Your java program, all your jars and classes are executed by the java virtual machine.

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.

If you need some functionality you should add it to your jar.




回答2:


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. But your jar may get in inconsistent state. Do it at your own risk.




回答3:


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




回答4:


The best way to update the rt.jar is to install a newer version for 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. 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. I wouldn't do this for production code, only for your own testing.




回答5:


I've tried jar.exe with the u and 0 (i.e. 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. No idea why! Simply running a program with the JRE seems to work.

I also tried -Xbootclasspath/p but couldn't get it to work.

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. So I plan to take the advice in that page and create a java agent. 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. One may also want to patch something. These would be for one's own use, of course.



来源:https://stackoverflow.com/questions/12119465/how-to-update-rt-jar-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!