Where are the Java System Packages stored? - java

I want to see all the java packages. Where are the packages stored in my machine? Can anyone help. I did search in jdk folder and found awt.dll and all. But its only a few. Can i see all of them?

If you want a list of packages in the standard installation, just go to the Javadocs and look in the upper left corner.
If you want to see the .class files, they're in lib\rt.jar in the JRE directory (.jar is the same as .zip, so you can open it with anything that can open zip files).
If you want to see the source code, look in src.zip in the JDK directory. If it's not there, you probably elected not to install it when you installed the JDK.
Keep in mind that packages are represented as folders on disk, so you might be a little disappointed by what you see.

From Java 9 onwards rt.jar was removed
The class and resource files previously stored in lib/rt.jar, lib/tools.jar, lib/dt.jar, and various other internal JAR files are now stored in a more efficient format in implementation-specific files in the lib directory. The format of these files is not specified and is subject to change without notice.
The System class files can now be accessed as shown below
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Path objClassFilePath = fs.getPath("modules", "java.base", "java/lang/Object.class");

Assuming you mean the packages that include the class libraries like java.lang.* and java.util.*, these live in the "lib" directory under wherever your Java Runtime Environment (JRE) is installed.
On Windows, it would be something like this:
C:\Program Files\Java\j2re1.4.2_12\lib
In there, you should see files like rt.jar which contains the core Java classes and charsets.jar which contains many of the extended encoding support for EBCDIC and the CJK languages.
In a parallel bin directory are the executables for Java and related utilities.
If you've installed the Java Development Kit (JDK), in the directory above where you find the libs you will probably find a src.jar file. This can be unpacked either with the jar.exe utility, or with a standard zip-style tool, and contains the Java sources to the standard class library.
Some of Java, such as the virtual machine itself, is machine-specific, and will be part of some of the DLL's or EXE's present.

You can try unzipping/unjarring rt.jar, which is usually available in $JAVA_HOME/lib/rt.jar. The jar file should include the classfiles of all the JDK, if that is what you are asking about.

Windows:
For compressed compiled java packages( Java Class Library, JCL): program files/java/jdk/jre/lib/rt.jar
For source of packages: program files/java/jdk/src.zip
we can use any unzipping software to look into them.

My JDK 1.6.0_13 has a src.zip containing all the source code. Give that a look.

As answered by #VenkataRaju i would like to put 2 more points that
we have ./bin, ./conf, ./include, ./jmods, ./legal, ./lib
we can see all the classlist in ./lib/classlist and ./lib/src.jar
in java 11

rt.jar is removed since Java 9. So, to find sources of JCL you should:
sudo find / -name java.base

Related

Where would one put a JNI module in Linux or OS X

The Java application has the JNI module to use.
Where should a user (or an installation script of this application) put the JNI module on Linux (Ubuntu) or on MacOS X so that this JNI module could be loaded without specifying the path to the module in code?
This is a link to a detailed explanation of shared objects and how they are searched for by the OS.
I wish Java people would stop using LD_LIBRARY_PATH and start using the existing directory structures and the ld.so.conf mechanism. Even the OpenJDK libraries are dumped in a place that's not on a standard path and they don't add an ld.so.conf file either ( just how hard is that ? ).
This approach avoids the need to set up your own LD_LIBRARY_PATH and launch via a shell script.
If a required shared object is to be installed, first test for somewhere like /usr/local/lib as an installation choice system wide, and if it exists and an existing file does not already use your file's name, then put your library there. A more systematic approach would be to check all the ld.so.conf files and see if any of the directories match something you know can be used. A shell script can do that at install time.
Put the compiled libraries (.so files on Linux or .dylib on MacOS) into a directory of your choice and include this directory in the library search path LD_LIBRARY_PATH used to start your JVM.

Modify src.zip file in jdk folder

Can I modify src.zip(it contains java classes predefined ) so that i
first unzip and then add my personal package and zip and replace the src.zip with this
new src.zip i modified.
so that i can import them just like any other classes.
Check out the Java tutorial on the CLASSPATH. That provides an extensible means of adding libraries for Java usage which doesn't impact the original install, and can be segregated between running processes.
The CLASSPATH variable is one way to tell applications, including the
JDK tools, where to look for user classes. (Classes that are part of
the JRE, JDK platform, and extensions should be defined through other
means, such as the bootstrap class path or the extensions directory.)
The preferred way to specify the class path is by using the -cp
command line switch. This allows the CLASSPATH to be set individually
for each application without affecting other applications
You'll rarely have to touch the JDK/JRE install, and I would strongly recommend against it. By using mechanisms such as the above, each app can specify its own libs, and you can swap between variants of the JDK/JRE without having to ensure each deployment is modified.
The src.zip contains the source files not the class files and it won't be part of the built in classpath either.
If you have to import your classes, you have to keep you other dependent jars in the classpath.
What you want is set the classpath.
Of cause, you can add your classes to the rt.jar file, but I highly recommend not to do so.
How to set the classpath
src.zip folder will not be included in java classpath, yes you can add your own classes in it. But in order to add it your classpath ,it needs to be compiled and the resulting class files you can add use.
But its not recommended to modify jdk source, unless you know exactly what you are trying to do.

How does one build the java JRE from source (src.zip in JDK)?

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.
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...
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?
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.
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.

What's wrong with the Java source code?

In the Java source from http://download.java.net/jdk6/source/ I get a jar of size ~130mb. The jar don't attach to Eclipse, and inside it has a file called "X_X" of size ~130mb.
Does anyone know what's happening?
--update
Thanks Gerco Drie,
now, about this README file:
JDK requires a high level of
technical expertise. (...) If you are not a
technical professional in one of these
categories, this release is probably
not for you.
so, where is the already buid one for me?
I'm using Java 6 update 15.
--update
The site http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/jdkfiles.html says the src.zip is in the root jdk folder (yes, I remember it was last time I needed it), but its not..
Is my jdk a pirate version? :P
You need to run the jarfile, not extract it or link it to eclipse. The instructions are here:
http://download.java.net/jdk6/6u20/promoted/b01/docs/build/README-JRL.html
These files are jar files that need to be run, not un-jar'd, for example: java -jar filename.jar
I think BalusC is right by the way, this is not the sourcecode you want. You probably want the rt.jar sourcecode, which is in src.zip with the JDK. What you downloaded is the complete sourcecode of the JVM, hotspot compiler, etc included. Although it also includes the class libraries, there is an easier way.
The distribution you download is a self-extracting file which displays a license YOU MUST ACCEPT before the things you need are extracted.
Run it, and see if it answers your issues.

Where are the class files located in JDK folder?

This may sound like a stupid question. Where are the core class files from Sun, like Button.class, located in the JDK installation folder C:\Program Files\Java\jdk1.5.0_12?
Or do the class files reside in C:\Program Files\Java\jre1.5.0_12 folder?
They are spread between several jars. It looks like Button is in jre/lib/rt.jar though.
The class files actually reside as jar files inside the Java distribution being used. Most files are in rt.jar (runtime).
Most developer machines actually have two forms of Java installed. The JDK (which you would often be using when developing and includes the compiler), and the JRE which is used by downloaded Java based applications, and often your web browser. Those are typically two independent distributions that don't know about each other. So the answer to your question is unfortunately, "depending what it is that you are running". To make things worse, the JDK may include it's own copy of the JRE...
This is one of the sources of the so-called classpath hell, because it is not always clear what you are using when you are running a java program.
If you run java from the command line, you can sometimes detect the exact version being used.
If you use Eclipse, you can pick version of the JDK you are working with.
On Both.
They are two different JVM's installations. One used to compile ( JDK stands for Java Development Kit )
and the other is the java environment which most customers machine have ( JRE stands for Java Runtime Environment )
Look on any of those two for a file named:
rt.jar
That where the core of the platform resides.
You can check out yourself for any class through reflection.
For example where can I find my String class located in the classpath?
Easy
URL url = String.class.getResource("String.class");
System.out.println(url);
There are actually contained in the JRE. Although, the JDK have her copy of the JRE so we may be tempted to say both JDK and JRE but in reality java inbuild classes are contained in the JRE.

Categories

Resources