天天看點

Maven和Eclipse聯合開發(轉)

最近公司突然把以前的架構推到從來,這個還真需要勇氣,不過也是的,基礎不好,再好的房子也站不穩.公司采用Maven作為項目管理,WebService項目架構采用SDHI.(Spring+Dubbo+Hessian+ibatis)

好了,直奔主題

1,我們當然需要一個Eclipse,我們需要安裝Maven的插件.經過測試,Maven好像對于Eclipse的版本到也不挑剔.我工作的環境Eclipse4.2(eclipse-jee-juno-SR2-win32.zip),但是我自己家裡開發環境Eclipse3.8(eclipse-jee-helios-SR1-win32.zip),都配置過,都能通行.

加載Maven插件:(以Eclipse4.2為例)

a,Eclipse -> Help -> Install New Sofeware.

b,Available Sofeware -> Work with -> Add.

c,Add Repository -> Name (maven 我自己定義的) -> Location (http://m2eclipse.sonatype.org/sites/m2e

) -> OK

d,Available Sofeware ->Maven Integration for Eclipse (selected) -> next -> ... ... (你懂的)

配置Maven:

a,Eclipse -> Window -> Preferences -> Maven -> Download repository index updates on startup (unselected) -> Apply

b,Maven -> User Setting -> Browse( ...../setting.xml 這個就是你的自己的Maven配置檔案,裡面有你通路的共庫和私庫等等之類資訊) -> Apply -> OK

加載SVN插件:

網上都列子,我就不多說了.

2,我們現在就可以構造我們的Maven工程了.

a,Eclipse -> New -> Project

b,New Project -> Selecte a wizard -> Maven ->Maven Project(selected) -> Next -> Next

這裡有一個小差異就是,如果你建立的不是WEB工程,那麼你需要就是 Next進行到下一步.

建立Maven WEB工程

Catalog -> Internal(selected) -> Filter -> webapp -> Group Id -> org.apache.maven.archetypes(selected) -> Next

c,New Maven Project -> Group Id (cn.haohaowo 這個就是你公司包名) -> Artifact Id (stu 項目名) -> Finished

在這裡要說一下,不知道是插件的原因還是其他原因,構造出來的WEB工程重要webapp目錄剛開始沒有顯示出來,需要手動添加一個目錄webapp.

stu(你的項目) -> New -> Source Folder

New Source Folder -> Folder Name -> src.main.java.webapp -> Finished

3,Maven利用Jetty容器開發.

我們要在項目pom.xml檔案中加如Build.

<build>

<finalName>hessian</finalName>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.5</source>

<target>1.5</target>

</configuration>

</plugin>

<groupId>org.mortbay.jetty</groupId>

<artifactId>maven-jetty-plugin</artifactId>

<scanIntervalSeconds>0</scanIntervalSeconds>

<connectors>

<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">

<port>8888</port>

<maxIdleTime>60000</maxIdleTime>

</connector>

</connectors>

</plugins>

</build>

stu(項目) -> Run As -> Maven Build

Edit Configuration -> Edit Configuration and launch -> Goals -> jetty:run -> Apply -> Run

你之後就可以像啟動一個項目一樣啟動Maven::Jetty. Run/Debug.

http://www.verydemo.com/demo_c293_i13336.html

繼續閱讀