eclipse把java web項目轉為maven項目__web

來源:互聯網
上載者:User

自己開發一個項目,建立的是dynamic web project,結果提交代碼交付給營運人員時,他們要求用maven項目,說這樣更好管理。苦於我以前maven用的太少了,那就學吧。

1.轉換項目類型

右鍵項目,看到有Configure選項,直接Convert To Maven Project,整個項目目錄會發生變化,如圖

多了maven的標誌性檔案pom.xml,在編輯框彈出如下

OK,已經轉為了maven項目,這裡可以編輯你的版本,Artifact Id等資訊。

2.編輯pom.xml

點擊下面的pom.xml,進入pom的編輯模式。

在普通的項目中我們只需要添加一些依賴項,我們可以到http://www.mvnrepository.com/去找相關的依賴包。

從項目的Referenced Libraries子目錄可以看到自己的依賴包,比如我的項目需要mahout包,那麼我去網站搜尋mahout,根據自己需要的包及版本,進入到以下頁面。

可以看到有個xml標記語言的dependency,把這個複製到自己的pom.xml中。下面是我的pom.xml部分代碼。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>SmartPush</groupId><artifactId>SmartPush</artifactId><packaging>war</packaging><dependencies><dependency><groupId>org.apache.mahout</groupId><artifactId>mahout-core</artifactId><version>0.9</version></dependency><dependency><groupId>org.apache.mahout</groupId><artifactId>mahout-math</artifactId><version>0.9</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.30</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency></dependencies><build><sourceDirectory>src</sourceDirectory><resources><resource><directory>src</directory><excludes><exclude>**/*.java</exclude></excludes></resource></resources><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>1.7</source><target>1.7</target></configuration></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>2.3</version><configuration><warSourceDirectory>WebContent</warSourceDirectory><failOnMissingWebXml>false</failOnMissingWebXml></configuration></plugin></plugins></build><version>0.0.1</version></project>

3.編譯

進入到自己的項目目錄,執行以下命令

$mvn compile$mvn package
你就可以在target目錄下看到需要的war檔案。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.