开发中的项目发现漏洞,需要升级 *.jar
版本及 Tomcat 版本。
项目初始初始选型与 SpringBoot 无缘,同时最初使用的是tomcat7-maven-plugin
来启动,公司要求开发软件正版化……
基于以上种种要求,软件版本升级面临的问题让人愈感压力巨大。虽然形势严峻,问题突出,压力巨大,但是工作还是要做的。
*.jar
文件升级很快,修改pom.xml
文件版本号,重新加载 Maven 修改即可。- apache 官网下载 tomcat 8.5.* 最新版本并替换。
配置完成,重新启动项目,开发环境运行正常,测试验证一次通过,生产上线。这一切只存在于幻想中。
方法一:tomcat7-maven-plugin
替换为tomcat8-maven-plugin
就出现错误
No plugin found for prefix 'tomcat8' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (......), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
参考多篇搜索结果配置大概如下,都无法达到目的,果断放弃。
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>3.0-r1756463</version>
</plugin>
</plugins>
</pluginManagement>
</build>
方法二:其他替代插件(未验证)
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
<version>1.9.12</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<home>${env.CATALINA_HOME}</home>
</container>
<configuration>
<type>existing</type>
<home>${env.CATALINA_HOME}</home>
</configuration>
<deployables>
<deployable>
<groupId>com.yourcompany</groupId>
<artifactId>ROOT</artifactId>
<type>war</type>
<properties>
<context>${project.build.finalName}</context>
</properties>
</deployable>
</deployables>
<deployer>
<type>installed</type>
</deployer>
</configuration>
</plugin>
方法三:针对社区版 IDEA,配置tomcat需要用到Smart Tomcat
File -> Settings... -> Plugins -> Smart Tomcat
在File -> Settings... -> Tomcat Server
配置Tomcat 路径。
Edit Configurations...
页面配置项目路径、端口号及参数。
Deployment Directory
一定要设置到webapp
级Context Path
设置为/projectName
即可VM options
可以设置VM参数,比如:-Dspring.profiles.active=test
,同时也需要把未加载的*.properties
文件参数-Dkey=value
也写入。否则出现参数无法找到的错误。Caused by: java.lang.NumberFormatException: For input string: "${key}"