6

Surprisingly enough I couldn't find the answer to this question.

I am trying to rebuild the java JRE from source. I obtain the java JRE source by extracting the src.zip file in the JDK.

After making any changes I need to make to the JRE, how do I compile the new source back into .java files (after which I can compress it into the rt.jar file).

Thanks.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Tom
  • 8,536
  • 31
  • 133
  • 232
  • What do you mean by `after making any changes I need` – Woot4Moo Feb 09 '11 at 18:31
  • @Woot4Moo, I simply mean that after editing the source of the JRE I wish to build it again to my custom version of the JRE. For example, I can edit Object.java so that every object has another field or some special function. I realize there are much better ways to do this, but I am just giving an example. – Tom Feb 09 '11 at 18:46
  • 1
    Are you getting any exceptions or errors?? Could you mention your approach? that would help others to see what is going wrong. – Favonius Feb 09 '11 at 18:58
  • @Favonius I haven't actually tried anything yet. I am looking for a source that tells me how to do this. Notice I am talking about the high level .java files for the JRE. I suppose they could be build with javac, but then one would need to add all those files to the files list manually? The files are in src.zip in the JDK. This is not the low level C source for the JDK itself. – Tom Feb 09 '11 at 19:05
  • I think you can only do this with this approach if you want to change a class that is part of the Endorsed Standards APIs: http://download.oracle.com/javase/6/docs/technotes/guides/standards/ – Puce Feb 09 '11 at 19:23
  • @Puce that list of endorsed APIs does not seem to include the standard JRE files like java.lang.* – Tom Feb 09 '11 at 19:33
  • Ah, there is also the bootclasspath which you could override: http://download.oracle.com/javase/6/docs/technotes/tools/solaris/java.html http://download.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html – Puce Feb 09 '11 at 19:46

4 Answers4

3

You have better chances using OpenJDK (the base of Oracle/ Sun's future JDKs). http://openjdk.java.net/

But what do you want to change actually? Maybe there is a better way...

Puce
  • 37,247
  • 13
  • 80
  • 152
  • I'm afraid the OpenJDK does not suffice (it does not support all java applications). Also, this should be a trivial task, as the source is right there and only has to be build. – Tom Feb 09 '11 at 18:47
  • 2
    The src.zip does not contain all the sources and I don't know what the license allows. OpenJDK needs some additional binaries which are not open source, but then all applications should run fine. – Puce Feb 09 '11 at 19:08
2

If you want to change a number of class, you only need to compile those classes. You don't need to compile the whole JDK unless you intend to replace it.

If you just want to patch it, create a JAR of your changed classes and add this to the boot class path.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • I guess I could compile every class that I modify one by one. It surprises me though that there is a source folder that apparently cannot be build easily (?). – Tom Feb 09 '11 at 19:35
  • 1
    Its meant for educational purposes. The JDK license discourages the modification of any standard library/class (lawyers may take a stronger view) You can compile the OpenJDK from scratch however. – Peter Lawrey Feb 09 '11 at 20:06
2

Some of the Java sources that make up rt.jar are generated during the build process, from scripts and other means. Some of the properties files are also generated this way, and some of the properties files are turned into Java source that also contributes to rt.jar. So without doing a complete build first and populating the 'gensrc' directory, you won't have all the sources that make up rt.jar.

Taken from: http://www.java.net/forum/topic/jdk/java-se-snapshots-project-feedback/it-possible-just-build-rtjar

So when you say javac on all the java files inside src.zip it won't compile as the dependency graph is broken (missing generated files)

Also have a look at this: Where to get full source code for rt.jar?

Community
  • 1
  • 1
Favonius
  • 13,959
  • 3
  • 55
  • 95
  • Thanks. What do they mean with a complete build? Building the C source of the JDK? – Tom Feb 09 '11 at 20:03
  • @Tom: Well as from the link it seems the complete build involves the execution of the scripts to generate boiler plate code and properties file. Although I am not too sure what else it may involve. Will keep updating my answer as i get something worth sharing. – Favonius Feb 09 '11 at 20:08
1

After revisiting the question. Javac on any of those files will allow you to rebuild them. Also you don't compile .java files into .java files they become .class files. You can write an ANT build script to handle the heavy work for you.

Woot4Moo
  • 23,987
  • 16
  • 94
  • 151
  • @Woot4Moo, I'm afraid that's meant for building the low level C source. I am simply talking about the java files for the rt.jar JRE file (it's in src.zip in the JDK folder, not the JDK's source). – Tom Feb 09 '11 at 19:03
  • I think this is also based on OpenJDK, isn't it? – Puce Feb 09 '11 at 19:10
  • @Woot4Moo: The link you mentioned before: http://download.java.net/jdk6/6u23/promoted/b05/docs/build/README-builds.html – Puce Feb 09 '11 at 19:13
  • @Puce ahh right, I suppose I never tried to build it from source. – Woot4Moo Feb 09 '11 at 19:14
  • Unfortunately it seems like the source cannot be build that easily with javac, there appear to be missing files or something. I cannot really point down the problem unfortunately. – Tom Feb 09 '11 at 19:35
  • @Tom it is probably the internal resources, using 7-zip you can open rt.jar and see the contents – Woot4Moo Feb 09 '11 at 19:38