创建配置文件.vscode/settings.json{ "java.jdt.ls.java.home": "/usr/lib/jdk-17.0.6-10", "java.compile.nullAnalysis.mode": "automatic", "java.configuration.runtimes":[ { "name": "JavaSE-1.8", "path": "/usr/lib/jdk1.8.0_281", }, { "name": "JavaSE-11", "path": "/usr/lib/jdk-11.0.11", }, { "name": "JavaSE-17", "path": "/usr/lib/jdk-17.0.6-10", "default": true } ], "java.configuration.updateBuildConfiguration": "automatic", "maven.terminal.customEnv": [ { "environmentVariable": "JAVA_HOME", "value": "/usr/lib/jdk1.8.0_281", },{ "environmentVariable": "MAVEN_OPTS", "value": "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" } ], "maven.executable.path": "/usr/local/apache-maven-3.8.1/bin/mvn", "maven.view": "hierarchical", "maven.executable.options": "-s /home/hadong/.m2/patsnap-settings.xml", "java.configuration.maven.userSettings": "/home/hadong/.m2/patsnap-settings.xml", "maven.settingsFile": "/home/hadong/.m2/patsnap-settings.xml", "java.debug.settings.onBuildFailureProceed": true, "java.import.gradle.java.home": "/usr/lib/jdk1.8.0_281", "java.import.gradle.wrapper.enabled": false, "java.import.gradle.version": "", "java.import.gradle.home": "/home/hadong/.sdkman/candidates/gradle/current/", "gradle.autoDetect": "on", "gradle.javaDebug.cleanOutput": true, "gradle.debug": true }.vscode/launch.json{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "java", "name": "Launch APP", "request": "launch", "mainClass": "com.patsnap.app.Application", "env": { "spring.profiles.active": "secret", "configs.com.patsnap.workspace.region": "DH", "configs.com.patsnap.dynamodb.table.track.ignore.regex.list": "workspace_folder_v2,workspace_task" }, "cwd": "${workspaceFolder}", "javaExec": "/usr/lib/jdk1.8.0_281/bin/java", "projectName": "workspace-service", "shortenCommandLine": "jarmanifest" } ] }
下载多个版本的JDKhttps://www.oracle.com/java/technologies/downloads/#java11解压到/usr/lib目录我安装了3个版本JDK/usr/lib/jdk1.8.0_281 /usr/lib/jdk-11.0.11 /usr/lib/jdk-17.0.6-10分别注册环境alternatives --install /usr/bin/java java /usr/lib/jdk1.8.0_281/bin/java 8 alternatives --install /usr/bin/java java /usr/lib/jdk-11.0.11/bin/java 11 alternatives --install /usr/bin/java java /usr/lib/jdk-17.0.6-10/bin/java 17刷新配置update-alternatives --config java source /etc/profile java -version
wget下载源文件wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz 解压tar包tar -zxvf jdk-8u111-linux-x64.tar.gz 创建文件夹并拷贝java文件sudo mkdir -pv /usr/java sudo cp -r jdk1.8.0_111/ /usr/java 配置环境变量sudo nano /etc/profile export JAVA_HOME=/usr/java/jdk1.8.0_111 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH //立即生效 source /etc/profile
Ubuntu在安装完eclipse后打开有时会遇到找不到jdk环境变量的错误：A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No java virtual machine was found after searching the following locations 解决方案如下：1. 进入eclipse，打开终端 2. mkdir jre 3. cd jre 4. ln -s /usr/lib/jvm/jdk1.7/bin bin --(你的JDK目录)
使用wget下载到本地//使用cookie模式下载 wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz //修改环境变量配置文件 sudo nano ~/.bashrc //在文件末尾加入下面的代码 export JAVA_HOME=/usr/local/java/jdk1.7.0_79 export JAVA=/usr/local/java/jdk1.7.0_79 export JRE_HOME=/usr/local/java/jdk1.7.0_79/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$PATH //应用新的环境变量 source ~/.bashrc