java 如何仅提取 JDK 安装程序的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2203922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:01:51  来源:igfitidea点击:

How to extract ONLY the contents of the JDK installer

installerinstallationextractjava

提问by Abel Morelos

I just downloaded the Java SDK/JDK versions 5 and 6, and I just need the development tools (and some libraries) contained in the installation packages, I don't need to perform an installation and that's why I was only looking for a zip package at first (for Windows there is only an exe installation file), I only need to extract the contents of the installation packages, I think this can be done from the command line but so far I haven't found how to do this (I already considered WinRar and 7-Zip, but I really want to find how to do it without using these tools)

我刚刚下载了 Java SDK/JDK 版本 5 和 6,我只需要安装包中包含的开发工具(和一些库),我不需要执行安装,这就是我只寻找 zip 的原因包一开始(对于Windows只有一个exe安装文件),我只需要提取安装包的内容,我认为这可以从命令行完成,但到目前为止我还没有找到如何做到这一点(我已经考虑过 WinRar 和 7-Zip,但我真的很想找到不使用这些工具的方法)

Have you done this before and how?

你以前这样做过吗?怎么做的?

采纳答案by Thorbj?rn Ravn Andersen

You can do the installation once and then zip up the installed stuff placed under \Programs\Java.

您可以进行一次安装,然后将安装的东西压缩到 \Programs\Java 下。

This can be unzipped elsewhere later and used as a JDK in most IDE's without needing a full reinstall (but then Windows does not know about it)

这可以稍后在其他地方解压缩,并在大多数 IDE 中用作 JDK,而无需完全重新安装(但 Windows 不知道它)

回答by E.Egiazarov

Here's .bat script for unpacking "pack" files. Must be run in the root of unzipped JDK.

这是用于解压缩“pack”文件的 .bat 脚本。必须在解压后的 JDK 的根目录中运行。

@echo off
echo **********************
echo unpack JDK pack-files
echo **********************
pause

set JAVA_HOME=c:\glassfish4\jdk7

setlocal enableextensions
for /r %%f in (*) do call :process %%f
endlocal
goto :eof

:process
if NOT "%~x1" == ".pack" goto :eof
set FOLDER=%~p1

set PWD=%CD%
pushd %FOLDER%
echo Unpacking %~nx1
%JAVA_HOME%\bin\unpack200.exe %~nx1 %~n1.jar
popd

goto :eof

回答by t0mm13b

I use 7-zip to do that. It seems to handle that installer/self-extracting executables nicely.

我使用 7-zip 来做到这一点。它似乎可以很好地处理安装程序/自解压可执行文件。

回答by 4ndrew

I've created cygwin script to do that: https://gist.github.com/4ndrew/f9dca61cedf0e8340b54

我已经创建了 cygwin 脚本来做到这一点:https: //gist.github.com/4ndrew/f9dca61cedf0e8340b54

#!/bin/sh
# usage example: prepareJdk.sh jdk-7u67-windows-x64.exe (result will be in jdk/)
# Requires: p7zip, unzip

JDK_EXE=
7z x -ojdk "$JDK_EXE"
unzip jdk/tools.zip -d jdk/

find jdk/ -type f \( -name "*.exe" -o -name "*.dll" \) -exec chmod u+rwx {} \;

rm jdk/tools.zip
find jdk/ -type f -name "*.pack" | while read eachFile; do
   echo "Unpacking $eachFile ...";
  ./jdk/bin/unpack200.exe $eachFile ${eachFile%.pack}.jar;
  rm $eachFile;
done

回答by Ergosum

You can extract both JDK 1.5 and 1.6 from .exe files, using the Universal Extractor (really a great tool). But don't forget to convert all *.pack files (compressed with Pack200format) into corresponding *.jar files, in order to obtain a full working environment. You can use the unpack200.exe command provided in the JDK itself.

您可以使用 Universal Extractor(非常棒的工具)从 .exe 文件中提取 JDK 1.5 和 1.6。但是不要忘记将所有*.pack 文件(用Pack200格式压缩)转换成相应的*.jar 文件,以获得完整的工作环境。可以使用JDK本身提供的unpack200.exe命令。

回答by Thimmayya

Maybe you can try Universal Extractor. The site looks legit, but I haven't tried it myself.

也许你可以试试Universal Extractor。该网站看起来合法,但我自己还没有尝试过。

回答by Andrea Scarpino

This is e-egiazarov's script, modified to use unpack200.exefrom the JDK archive and also to remove the pack file after conversion.

这是e-egiazarov的脚本,经过修改以unpack200.exe从 JDK 存档中使用,并在转换后删除包文件。

@echo off

setlocal enableextensions
for /r %%f in (*) do call :process %%f
endlocal
goto :eof

:process
if NOT "%~x1" == ".pack" goto :eof
set FOLDER=%~p1

set PWD=%CD%
pushd %FOLDER%
echo Unpacking %~nx1
%PWD%\bin\unpack200.exe %~nx1 %~n1.jar
del %~nx1
popd

goto :eof

回答by user2173403

a little late to the party

参加晚会有点晚

here's an extractor written in powershell

这是一个用powershell编写的提取器

param($installdir)

$list=$(gci -Recurse ./$installdir/*.pack) | %{
    return @{
        source=$_.FullName
        parent=$_.Directory.FullName
        target="$($_.Directory.FullName)$([io.path]::GetFileNameWithoutExtension($_.Name)).jar"
    }
} | %{
    $result = $(unpack200 $_.source $_.target)
    $_result=$result
    return $_
}

Write-Host $(ConvertTo-Json $list)