Do-it-yourself extract jdk

Why does the official not provide a green decompressed version of jdk?

Java developers under the windows platform may notice the phenomenon. When installing the windows version of the jdk, you have to click the next step step by step. Most of the same java developers have deployed tomcat or installed jdk on the Linux system, and downloaded one from the Oracle official website. tar compressed package, it is OK to configure the environment variables after decompression, and the installation under the windows system installs jre and automatic update program by the way, what about only installing jdk?

Only installed jdk? nonexistent

It is more convenient to install jdk under the windows platform. Double-click an exe file. Careful users may notice that during the installation of jdk, Oracle will also 诱导install a jre and an automatic update program (the location of jre and jdk are side by side, automatic The update program can be seen from the "Programs and Features" list in the control panel). In fact, as a java developer, it is not necessary to install a jre alone, because the jdk already comes with a jre.

To install an installed version of jdk, the work done is as follows:

  • Double-click to install jdk, install a jre in the process
  • Configure the environment variable JAVA_HOME PATH
  • Configure CLASSPATH. In fact, this step is unnecessary. I have never configured it on my machine, and there has been no problem.
  • win+r, enter cmd, enter, then enter java and enter, it shows that the usage of java is installed successfully, the online tutorials say to use java -version, I just feel that there is too much input.

In fact, more than that, after installation...

  • It will also create a new folder Java and the under it in your C:\ProgramData\Oracle directory, there is a folder called javapath (its icon is a shortcut icon, but it is actually a folder!!!), All folders starting with javapath have java.exe, javaw.exe, javaws.exe. (I have encountered a problem before that eclipse cannot be opened, because the javaw.exe found by eclipse is in this folder, and it is normal to force the configuration of eclipse to point to the real location)
  • The most annoying thing is that an upgrade program will be generated! It is in the C:\Program Files (x86)\Common Files\Java\Java Update directory.

In fact, as a java developer, as long as I configure JAVA_HOME and can use the java command, it can be said that the environment is successfully built. And look at how dishonest the windows version of the jdk is, it's really not as good as the linux version.

Green software VS installation package

Under the windows platform, many people like to use green software, because it is ready to use after decompression. If there is one more step, just click a bat file again. And installing a software is actually nothing more than putting some files into the corresponding directory. jdk is no exception. In fact, it is also possible to package and send the jdk directory you installed to another person (I only tried windows7 for windows7, and win10 did not test win10). Another feature of green software is to achieve the maximum function with the smallest volume. A common example is the various simplified versions of PhotoShop. I used a 20M ps8 before, which can meet my daily needs, so I don’t need to install that The original installation package of G.

Do-it-yourself extract jdk

The problem is very clear, we just want a green version of jdk, and we searched a lot on the Internet, but another problem came, I was afraid that the jdk downloaded from the Internet might have a virus. Or someone will ask, how did they extract the green version of jdk. In the final analysis, it is the same problem - how to extract jdk by yourself.

We can download a windows installation package from Oracle's official website, here I use jdk-8u121-x64.

The next step is to extract, we have to use an artifact 7-zip, yes, it is a compression and decompression software itself, but it has a little more function than WinRAR - it can decompress non-compressed package files! The steps are as follows, please follow the steps step by step:

  • Install 7-zip
  • Right-click the jdk installation package, click "Extract to "jdk-8u121-windows-x64/"", a folder with the same name as the installation package will be generated in the current directory
  • Enter the .rsrc/1033 folder, and you will see several folders starting with JAVA_CAB, as follows:
  • The files in JAVA_CAB7 are opened with 7-zip (right-click the file and click "Extract to the current location", the same below) and you will see the jre.exe file. We don't need this file because we want to extract jdk.
  • Inside JAVA_CAB9 is src.zip, which is the source code of java classes in jdk.
  • Inside JAVA_CAB10 is tools.zip. After opening it, you will find the same directory and file as the JDK installation directory. In fact, it is JAVA_HOME. Unzip tools.zip and copy it to a folder such as (c:/jdk8), In the future, this c:/jdk8 is JAVA_HOME, and then unzip the src.zip file in the previous step and put it in the c:/jdk8 directory. Be careful not to unzip the src.zip.
  • Inside JAVA_CAB11 is a COPYRIGHT file, which can be ignored.
  • (Feeling, why do I say feeling) The extraction is done, and then try the java command. Go to the c:/jdk8/bin directory, run cmd, enter java -version, unfortunately

    Error occurred during initialization of VM

    java/lang/NoClassDefFoundError: java/lang/Object

Said that java.lang.Object was not found, causing JVM initialization to fail. I got stuck here at the beginning.

Suddenly found a page on the Internet http://blog.csdn.net/x_iya/article/details/78305917, the end of the blog mentioned another pure English website https://bgasparotto.com/convert-jdk-exe-zip/. At this step, only one command is required to resolve the above error message, the command is

for /r %x in (*.pack) do .\bin\unpack200 -r "%x" "%~dx%~px%~nx.jar"

Please use this command in the c:/jdk8 directory. Then execute it in the cloud bin directory, java -versionand you will find that it is normal. Then configure JAVA_HOME and it's ok.

Affiliated Description

  • I tested it with jdk-8u121. Before converting the pack file into a jar file, the rt.pack was only 15.8M, but after converting it into rt.jar, it became 60.4M, which is amazing!

  • https://bgasparotto.com/extract-src-zip-jdk-installer/This page also says how to extract src.zip. In fact, it is the easiest to extract directly from JAVA_CAB9. In fact, there is another way to extract jdk, as mentioned in the file, first double-click to run the jdk installation package. At this time, don't click anything, go to %USERPROFILE%\AppData\LocalLow\Oracle\Java\jdk1.8.0_121_x64the directory (please copy and paste it directly into the address bar and press Enter), you will see a few A cab file is actually the same as the one decompressed with 7-zip. That page said that %USERPROFILE%\AppData\LocalLow\Oracle\Java\jdk1.8.0_121_x64the cab file in the directory will disappear after you install it successfully. I tested it on windows7 SP1 and found that the file did not disappear after the installation was successful..., attach a picture:cab file not disappearing

  • Please try to search in Baidu and Google respectively windows jdk 提取绿色版to experience the matching results...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324934318&siteId=291194637