Tag Archives: user.home

The problem of user.home environment variable in Java

Open source software supply chain lighting plan, waiting for you>>>

In the afternoon, several “weird” problems occurred in the process of development

first, when developing in idea, java.util.map class in JDK cannot be imported automatically. Java. Util. Map is not found in the list of auto prompts through online search, it is found that many people have encountered such problems. But the solutions are different. Some people mentioned the problem of JDK version conflict
using everything to search java.exe on my PC, I found that there were multiple versions of java.exe. When I located to the idea, I started it with jdk8, while the JDK configured in the development project was 1.7

after trying to uninstall jdk8, restart idea and prompt to select setting directory (i.e. idea directory).
select the. Idea directory under the current user directory in windows and start OK
when you enter map in the edit, you can automatically prompt java.util.map, which seems to be the problem of JDK version conflict I think I can finally develop it happily, and I feel very happy

a more “weird” problem followed
before compiling OK projects, all of them were prompted with mutation errors, and no third-party jars could be found
these jars are all in the Maven image library of the company. What the hell is this NIMA?It’s an unpleasant job
Ctrl + Alt + s open the configuration dialog box of idea, locate Maven in build tools, and find the problem

a

The default settings.xml file used by Maven points to D:// documents \. M2 \ \ settings.xml, and the default repository also points to D:// documents \. M2 \ \ repository. We found the problem. Previously, we used the settings.xml in the root directory of the current user in windows, and the central repository configured here uses the internal image of the company, However, there is no settings.xml file in D:// documents \. M2, so the default central library is used. Of course, the internal jar of the company cannot be found. However, why is this?Why does the default library path of Maven change when jdk8 is unloaded?After looking at the settings.xml file, the default repository path is ${user. Home} /. M2/repository. I thought that after uninstalling jdk8, I would restart idea and prompt to select the configuration file directory (I would not prompt again after starting configuration once before). It should be judged here that the value of the environment variable user. Home has changed
wrote a test case

System.out.println(System.getProperty("user.home"));

The output is exactly the directory D: documents
after searching on the Internet, it turns out that this is a bug in jdk1.7 and previous versions, which has been modified since 1.8. http://bugs.java.com/view_ bug.do?bug_ Id = 4787931
jdk1.7 and earlier versions set the user.home environment variable through the registry key
[HKEY_ CURRENT_ User/software/Microsoft/Windows/CurrentVersion/Explorer/shell folders/desktop]
get the value, and then get the superior directory of this path. Use regedit to view the value of the registry key on the PC, which is D:: – documents  desktop. This is a computer provided by the company. Switch the user’s desktop directory to D:  documents  so that personal data will not be lost after the system is reinstalled< after locating the problem, there are many solutions:
1. The path of override settings.xml and repository in idea
2. Execute MVN command-line to add – S C:: (users) ﹣ Jack ﹣ M2 ﹣ settings. XML
3. Copy C: ﹣ users ﹣ Jack ﹣ m2 to D: ﹣ documents ﹣ directory
3