1

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 9
    Noooooo!!!! Don't do it!!!!!! – paulsm4 Aug 25 '12 at 05:34
  • 4
    It's just a jar file, so you can use the `u` option of the `jar` tool to update it. However, you should never, ever do this. Thinking that you should is a strong sign that you don't understand the platform. – erickson Aug 25 '12 at 05:35

5 Answers5

5

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.

anio
  • 8,903
  • 7
  • 35
  • 53
1

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.

Nandkumar Tekale
  • 16,024
  • 8
  • 58
  • 85
1

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

Vinesh
  • 933
  • 2
  • 7
  • 22
1

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

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.

Garr Lystad
  • 41
  • 1
  • 5