小工具知识网

当前位置: 首页 > 行业知识 > 完全从零Java自学系列【工具篇】(JD-GUI反编译工具&mac与windows安装使用)

行业知识

完全从零Java自学系列【工具篇】(JD-GUI反编译工具&mac与windows安装使用)

2026-11-02 23:37:57 来源:互联网转载

文章目录

    • 概要
    • JAVA编译时的优化点其中之一
    • JD-GUI安装
      • 下载
        • windows
        • mac
        • 开源库说明

          概要

            JD-GUI反编译工具是非常轻量化的,且开源的反编译工具。它的使用场景有:

          1. 校验我们的编译结果是否正确(类的逻辑是否正确)(为什么执行结果不是和理想的一样?)。
          2. 我们的依赖是否已经一起打包了(第三方包)(为什么依赖了jar包运行时却报错找不到类?)。
          3. 代码优化(JAVA中优化的三大点:编译-执行-管理),此工具可以用于作为优化编译期间的参考点。

          JAVA编译时的优化点其中之一

            区别演示(左java,右class):

          1. 所有的注释内容都被去除了,一是没有必要注释是给人看的,二是缩小文件大小自
          2. public Grammar() {}构造函数默认是存在的,当你没有写别的重载构造函数时。
          3. 源码使用for循环,class文件却使用了while(true)
          4. 将int customerInput调整到了int customerInput = scanner.nextInt();
          5. 将break优化为了return。

          JD-GUI安装

          下载

          JD-GUI开源链接JD-GUI GITHUB

          windows

          windows下载 jd-gui-windows-1.6.6.zip

          解压后可以直接运行。

          mac

          下载jd-gui-osx-1.6.6.tar

          如果mac遇到无法验证开发者问题从下面解决:

          - 如果出现 ERROR launching ‘JD-GUI’

          No suitable Java version found on your system!

          This program requires Java 1.8+

          Make sure you install the required Java version.

          - 则需要通过右击,显示包内容,找到Contents/MacOS/universalJavaApplicationStub.sh

          - 并且将内容替换为以下内容即可

          #!/bin/bash###################################################################################                                 ## universalJavaApplicationStub    ##                                 ## A BASH based JavaApplicationStub for Java Apps on Mac OS X                     ## that works with both Apple's and Oracle's plist format.                        ##                                 ## Inspired by Ian Roberts stackoverflow answer                                   ## at http://stackoverflow.com/a/17546508/1128689                                 ##                                 ## @author    Tobias Fischer       ## @url       https://github.com/tofi86/universalJavaApplicationStub              ## @date      2021-02-21           ## @version   3.2.0                ##                                 ####################################################################################                                 ## The MIT License (MIT)           ##                                 ## Copyright (c) 2014-2021 Tobias Fischer                                         ##                                 ## Permission is hereby granted, free of charge, to any person obtaining a copy   ## of this software and associated documentation files (the "Software"), to deal  ## in the Software without restriction, including without limitation the rights   ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      ## copies of the Software, and to permit persons to whom the Software is          ## furnished to do so, subject to the following conditions:                       ##                                 ## The above copyright notice and this permission notice shall be included in all ## copies or substantial portions of the Software.                                ##                                 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR     ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,       ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  ## SOFTWARE.                       ##                                 ###################################################################################   # function 'stub_logger()'## A logger which logs to the macOS Console.app using the 'syslog' command## @param1  the log message# @return  void################################################################################function stub_logger() {syslog -s -k \Facility com.apple.console \Level Notice \Sender "$(basename "")" \Message "[$$][${CFBundleName:-$(basename "")}] "}   # set the directory abspath of the current# shell script with symlinks being resolved############################################ PRG=while [ -h "$PRG" ]; dols=$(ls -ld "$PRG")link=$(expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null)if expr "$link" : '^/' 2> /dev/null >/dev/null; thenPRG="$link"elsePRG="$(dirname "$PRG")/$link"fidonePROGDIR=$(dirname "$PRG")stub_logger "[StubDir] $PROGDIR"   # set files and folders############################################ # the absolute path of the app packagecd "$PROGDIR"/../../ || exit 11AppPackageFolder=$(pwd) # the base path of the app packagecd .. || exit 12AppPackageRoot=$(pwd) # set Apple's Java folderAppleJavaFolder="${AppPackageFolder}"/Contents/Resources/Java # set Apple's Resources folderAppleResourcesFolder="${AppPackageFolder}"/Contents/Resources # set Oracle's Java folderOracleJavaFolder="${AppPackageFolder}"/Contents/Java # set Oracle's Resources folderOracleResourcesFolder="${AppPackageFolder}"/Contents/Resources # set path to Info.plist in bundleInfoPlistFile="${AppPackageFolder}"/Contents/Info.plist # set the default JVM Version to a null stringJVMVersion=""JVMMaxVersion=""   # function 'plist_get()'## read a specific Plist key with 'PlistBuddy' utility## @param1  the Plist key with leading colon ':'# @return  the value as String or Array################################################################################plist_get(){/usr/libexec/PlistBuddy -c "print " "${InfoPlistFile}" 2> /dev/null} # function 'plist_get_java()'## read a specific Plist key with 'PlistBuddy' utility# in the 'Java' or 'JavaX' dictionary ()## @param1  the Plist :Java(X):Key with leading colon ':'# @return  the value as String or Array################################################################################plist_get_java(){plist_get ${JavaKey:-":Java"}}   # read Info.plist and extract JVM options############################################ # read the program name from CFBundleNameCFBundleName=$(plist_get ':CFBundleName') # read the icon file nameCFBundleIconFile=$(plist_get ':CFBundleIconFile')  # check Info.plist for Apple style Java keys -> if key :Java is present, parse in apple mode/usr/libexec/PlistBuddy -c "print :Java" "${InfoPlistFile}" > /dev/null 2>&1exitcode=$?JavaKey=":Java" # if no :Java key is present, check Info.plist for universalJavaApplication style JavaX keys -> if key :JavaX is present, parse in apple modeif [ $exitcode -ne 0 ]; then/usr/libexec/PlistBuddy -c "print :JavaX" "${InfoPlistFile}" > /dev/null 2>&1exitcode=$?JavaKey=":JavaX"fi  # read 'Info.plist' file in Apple style if exit code returns 0 (true, ':Java' key is present)if [ $exitcode -eq 0 ]; thenstub_logger "[PlistStyle] Apple" # set Java and Resources folderJavaFolder="${AppleJavaFolder}"ResourcesFolder="${AppleResourcesFolder}" # set expandable variablesAPP_ROOT="${AppPackageFolder}"APP_PACKAGE="${AppPackageFolder}"JAVAROOT="${AppleJavaFolder}"USER_HOME="$HOME"  # read the Java WorkingDirectoryJVMWorkDir=$(plist_get_java ':WorkingDirectory' | xargs)# set Working Directory based upon PList valueif [[ ! -z ${JVMWorkDir} ]]; thenWorkingDirectory="${JVMWorkDir}"else# AppPackageRoot is the standard WorkingDirectory when the script is startedWorkingDirectory="${AppPackageRoot}"fi# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOMEWorkingDirectory=$(eval echo "${WorkingDirectory}")  # read the MainClass nameJVMMainClass="$(plist_get_java ':MainClass')" # read the SplashFile nameJVMSplashFile=$(plist_get_java ':SplashFile') # read the JVM Properties as an array and retain spacesIFS=$'\t\n'JVMOptions=($(xargs -n1 

上一篇:crisps快速记忆怎么记?

下一篇:英语高手揭秘,如何正确表达好友之情!