如何在 IDEA 中使用Maven 及 相應插件


1,Maven 面板

image

 

 

Root ,相當於 VS 中的 sln ? ,大概可以這樣理解吧。

 

clean  --> install  這樣操作, 所有的項目都會被執行。

手工操作有點麻煩。換另一種方式

在控制台執行

 

image

 

 

mvn clean install -Dmaven.test.skip=true –X  
與上面的命令相似的

    mvn install  -Dmaven.test.skip=true -Djar.forceCreation  -X  (試用后感覺這條比clean 好些, clean 會刪除文件,如果正在熱部署,會產生文件鎖定的可能性無法刪除,這條暫時還沒遇到)

 
其它的命令還有
mvn clean compile、mvn clean test、mvn clean package、mvn clean install
 
 
2,啟動WEB容器
 
一般情況下,推薦使用 集成容器, 為什么呢?在 VS開發中,現在誰不用IIS Express 去運行,調試代碼呢?
 
image
 
jetty和tomcat 都可以,一般 我用 jetty , 大家都說jetty快, 我也沒覺得,心理作用吧。不過, java web 容器的啟動真是無語。慢或者出錯就啟不來了
另外,我已經將 這兩個插件配置成為熱部署, (也就是 容器檢測到內容的改變,會自動重啟加載)
 
下面是Pom中與之相應的配置節點
 
<build>
<plugins>


<!--tomcat7插件-->
<!--https://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/run-mojo.html-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat7-maven-plugin.version}</version>
<configuration>
<path>${tomcat-path.version}</path>
<port>${tomcat-port.version}</port>
<uriEncoding>${tomcat-uri-encoding.version}</uriEncoding>
<url>http://localhost:8080/manager/text</url>
<server>tomcat7</server>
<username>admin</username>
<password>admin</password>
<contextReloadable>true</contextReloadable>
<update>true</update>
</configuration>
</plugin>

<!--jetty插件-->
<!--http://www.eclipse.org/jetty/documentation/9.0.0.M3/jetty-maven-plugin.html-->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-plugin.version}</version>
<configuration>
<stopKey>foo</stopKey>
<stopPort>8081</stopPort>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>${jetty-port.version}</port>
</connector>
</connectors>
<webApp>
<contextPath>${jetty-path.version}</contextPath>
</webApp>
<!--scanIntervalSeconds 可選[秒]。在很短的時間間隔內在掃描web應用檢查是否有改變,如果發覺有任何改變則自動熱部署。默認為0,表示禁用熱部署檢查。任何一個大於0的數字都將表示啟用。-->
<scanIntervalSeconds>1</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM