Home >Java >javaTutorial >jdk becomes jre after Maven refreshes

jdk becomes jre after Maven refreshes

巴扎黑
巴扎黑Original
2017-06-26 09:56:262643browse

Maven has two ways to set jdk, setting in setting.xml or pom.xml, and there are two ways to set it in pom.

If set in setting.xml, it is set as a global variable. Add the following profile element under the profiles element in the setting.xml file

<profile>  
    <id>jdk18</id>  
    <activation>  
        <activeByDefault>true</activeByDefault>  
        <jdk>1.8</jdk>  
    </activation>  
    <properties>  
        <maven.compiler.source>1.8</maven.compiler.source>  
        <maven.compiler.target>1.8</maven.compiler.target>  
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
    </properties>   
</profile>

Then if you set it in the pom.xml of each project, it will be a local variable.

<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
</build>

Also

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<encoding>UTF-8</encoding>
		<java.version>1.8</java.version>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
	</properties>

All of the above can specify the jdk version

But there is one more The problem is that after maven specifies jdk, he can only use the javase1.8 he specified. If the jdk setting is not correct at this time, something like this will happen

used lib is the jre version. If maven is used for packaging and other operations at this time, it will prompt

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Open Window - Preferences - java - Installed JREs

I found that jre is used instead of jdk

At this time You need to add jdk and switch to jdk

, but an error is still reported when compiling.

Look back at the project's java build path

I found the above javaSE-1.8 (jre1.8.0_131), which uses It's jre instead of jdk

and there is no jdk option when opening the option.

This is because jre was used instead of jdk at the beginning, causing the default javaSE to use jre.

You only need to delete the jre JREs in the Installed JREs

The above is the detailed content of jdk becomes jre after Maven refreshes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn