直达解决方法,请拉到最后!
今天掉进了一个坑,坑虽小,但本人觉得很有必要记录一下。
背景: 在eclipse上用maven搭建 javaWeb,然后配置tomcat等插件跑项目,使用tomcat:run,tomcat7:run,cargo:start,及jetty:run等
有出现插件无法加载,或者以下错误信息的
[ERROR] Error resolving version for plugin 'org.apache.tomcat.maven:tomcat7-maven-plugin' from the repositories
[local (/home/gitlab-runner/maven/repo), central (http://repo1.maven.org/maven2)]:
Plugin not found in any plugin repository -> [Help 1]
或
WagonTransporterFactory: java.util.NoSuchElementException
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:3.1.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:3.1.0: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:3.1.0 from/to public (http://******************.com/nexus/content/groups/public/): Cannot access http://******************.com/nexus/content/groups/public/ with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access http://******************.com/nexus/content/groups/public/ using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
[ERROR] role: org.apache.maven.wagon.Wagon
[ERROR] roleHint: http
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
或
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 23 in the generated java file
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
或者是带有
PluginResolutionException等
检查自己的jdk版本是不是过低了
我尝试了网上的很多方法,都没能解决以上异常,最后猜测是不是jdk的问题,可我明明在eclipse设置了jdk1.7,但是我一看居然是这个!!!
原来maven默认把工程设置为jdk1.5的了,虽然我有尝试过重新设置工程的jdk版本,但是不知道为什么没有生效。 我也没想到当前最新版的maven默认设置也是这么低,没想到要改它的setting,呜呜呜呜,坑了我好久
解决方法
在maven的conf文件夹下,在标签中加入以下一段,修改maven默认的jdk版本,我需要用的是1.7,其他的用1.8改1.8,用11改成11
<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>
然后,重新导入工程,发现可以了!
如果还是不行,那可能不是这个原因导致的,请自行搜索吧
(;一_一)(#-.-)(╯°Д°)╯︵┴┴╰(‵□′)╯