maven项目一些注意的地方

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lys1695227550/article/details/81026356

1、jdk编译版本

全局配置:

setting.xml中配置

<!--配置maven 默认jdk编译版本-->
<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>

局部配置:

pom.xml中配置

                                <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>

</plugin>

2、Apache Maven 3.5.4使用命令tomcat:run是使用自带的tomcat6,由于版本低,你可能需要使用更高版本,所以可以使用自己的安装的高版本tomcat,或者是插件,这里使用插件:

                        <plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/testMaven</path>
<port>8888</port>
<server>tomcat7</server>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>

</plugin>

3、如果新创建的maven web项目,出现The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的错误,这时不需要像以前的普通web项目那样添加servlet-api.jar,主需要添加项目依赖即可

                <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1-b01</version>
<scope>provided</scope>

</dependency


4、使用maven配置ssm项目时,使用的是tomcat7插件,但是每次修改都要重启,所以想使修改代码不要重启tomcat,这样就遇到一个问题就是run on server时,会出现

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

这时检查项目部署的位置,发现在WEB-INF下没有lib文件夹,因为我们使用的是maven管理jar包,所以此时需要一个配置,那就是:

右键点击项目

选择Properties

选择Deployment Assembly

在右边点击Add按钮

在弹出的窗口中选择Java Build Path Entries

点击Next,选择Maven Dependencies

反正最后你要整出如下图界面


查看部署位置,发现lib已经部署成功,为啥在这位置,具体看tomcat的server locations,配置可以参考我的其他文章。


最后运行成功。





猜你喜欢

转载自blog.csdn.net/lys1695227550/article/details/81026356