In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve jdk in linux to switch versions at any time, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Project processing problems encountered the following situation, citing a third-party jar package to report ClassDefNotFoundException errors leading to app crash, the two sides communicate to confirm the existence of this class and rule out the project is not clean, code confusion and other reasons.
Notice that compiling app prompts a lot of information that is different from normal:
Trouble processing:
Bad class file magic (cafebabe) or version (0033.0000)
... while parsing com/baidu/mapapi/SDKInitializer.class
... while processing com/baidu/mapapi/SDKInitializer.class
279 warnings
SDKInitializer is the class that ClassDefNotFoundException reported an error.
Baidu search for this compilation prompt found the cause of the problem: the third-party company packaged the jar package using a version of jdk1.7 (greater than 1.6), while we compiled app using version 1.6. due to the inconsistent version of the compiled bytecode, it could not be converted into bytecode scaled by the android virtual machine, so the referenced jar package was not actually compiled into the current apk. Of course, you can't find the corresponding class when the program is running.
The company compilation server is actually configured with multiple jdk versions, and android compilation is the jdk version that is set when the environment variable is set. Android4.4 is compiled using jdk1.6, while android5.0 is compiled using jdk1.7, which involves how to switch between jdk versions at any time.
Let's first take a look at how to set the jdk environment variable. Most of the answers from Baidu search are to modify ~ / .bashrc or modify / etc/profile file to complete the configuration at one time. I opened the two files with vi and did not find the corresponding jdk environment variables, but using java-version did see the default jdk version. This raises the question, where are the environment variables for the current default jdk software configured?
Use the which java command to find the location of the current java executable
Fordreamxin@compiler207:~$ which java
/ usr/bin/java
Most of the software installed by users is stored in the / usr/bin/ directory.
Fordreamxin@compiler207:~$ ll / usr/bin/java
Lrwxrwxrwx 1 root root 22 Nov 13 06:18 / usr/bin/java-> / etc/alternatives/java*
Alternatives is a multi-version management software under linux, which can be used to switch versions of jdk, which will be described later. First, let's take a look at what's in the alternatives directory.
Fordreamxin@compiler207:/etc/alternatives$ ls java*
Java java.1.gz javac javac.1.gz javadoc javadoc.1.gz javah javah.1.gz javap javap.1.gz java_vm javaws javaws.1.gz
Fordreamxin@compiler207:/etc/alternatives$ ll java
Lrwxrwxrwx 1 root root 36 Nov 13 06:17 java- > / usr/lib/jvm/java-6-sun/jre/bin/java*
It turns out that there are a lot of software version references under this directory, from which you can find the actual location of the current software version (jdk).
Fordreamxin@compiler207:/etc/alternatives$ ls / usr/lib/jvm/
Java-1.7.0-openjdk-amd64 java-6-sun java-6-sun-1.6.0.26 java-7-openjdk-amd64
Various jdk versions of the software are stored in the / usr/lib/jvm folder for time, and alternatives achieves the purpose of version switching by modifying its java reference.
The method of version switching using alternatives is as follows:
1. Check whether the corresponding jdk is in the jdk menu of ubuntu, and check:
Update-alternatives-config java
Update-alternatives-config javac
two。 If it is not in the menu, you can add it as follows:
Update-alternatives-install / usr/bin/java java/ usr/lib/jvm/java/jdk1.6.0_12/bin/java 300
Update-alternatives-install / usr/bin/javac javac / usr/lib/jvm/java/jdk1.6.0_12/bin/javac 300
Note: different versions of jdk1.6.0_12 will change.
3.sudo update-alternatives-config java
Sudo update-alternatives-config javac
Select the serial number and enter.
4. Then java-version,javac-version to view the current jdk version
However, using alternatives requires sudo super permission, that is, this switch is a global switch, which is the same as modifying ~ / .bashrc or / etc/profile. What if you don't have super privileges?
Setting the environment variable linux provides the export command, which is modified only for the current terminal.
Fordreamxin@compiler207:/$ echo $PATH
/ usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
The above command shows the current environment variables, that is, the contents of the ~ / .bashrc or / etc/profile file, which represents all the current environment variables of all software or commands that can be used globally. Without these variables, we can not use many commands or software in any directory, which is the meaning of environment variables.
Add the environment variable of jdk at the beginning or end of $PATH with the following command (executable commands such as java, javac, javah, etc., are saved in the bin directory)
Export PATH= "/ usr/lib/jvm/java-7-openjdk-amd64/bin": $PATH
Export PATH= "$PATH:/usr/lib/jvm/java-7-openjdk-amd64/bin/"
Since execution always searches for the location of the executable file at the beginning of $PATH, it is useful to set the new jdk at the beginning of PATH if a jdk is already set in the environment variable.
The above is all the contents of the article "how to switch versions of jdk at any time in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.