When I was learning Maven Web project development today, after importing Servlet dependencies in pom.xml and implementing the Servelet interface, I was prompted with the following error when I started Tomcat to run the project file.
Good guy, it really didn’t provide any prompt information, so I tried the cd command to the project, mvn compile, and it prompted an error message.
The general meaning is that the pom file was not found.
I searched the Internet for the reason: it may be a problem with the JDK version compiled by Maven. The default JDK version number of Maven is 1.5. Many syntaxes are not supported now, such as @Override, so you need to modify your Maven JDK default version.
Methods as below:
Open the conf directory under Maven. This directory stores some configuration files.
There is a setting.xml file here, open it for editing
Add this code under the profiles node (these selected)
The code is posted separately here for easy copying.
<profile>
<id>jdk-1.7</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.7</jdk>
</activation>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
</properties>
</profile>
After saving, it will be ok. Restart Tomcat to run the project and it will compile normally.
Written at the back: There are many ways to modify the JDK version used by Maven. Here is a big guy who has summarized how to modify the default JDK version of Maven_java_Script Home (jb51.net)y https://www.jb51. net/article/234994.htm
Usually the first method solves the problem, it is also the fastest and most trouble-free, and it can be solved once and for all.
Remember this is the first time I encountered this problem. I will add it next time I encounter other situations and dig a hole.