2011-03-23 47 views
6

我有一個工作或大多數正在工作的POM,它可以讀取所有的文件,而且完全只是對編寫Facelets應用程序感興趣的JAR。我正在使用m2eclipse。當我導入新創建的Maven創建的應用程序時,它會像預期的那樣乾淨地或多或少地出現,但是,它不像動態Web項目那樣,當我嘗試運行它時,它不提供運行方式 - >在服務器上運行選項。如何爲Eclipse創建Web應用程序的Maven原型?

我研究了其他Maven生成的Eclipse項目,它們可以在服務器上運行,但它們的工作原理(但不要使用JAR組合來設置)。例如,這一個工程,但它沒有得到我想要的JAR文件:

MVN原型:產生-DarchetypeArtifactId = Maven的原型 - web應用程序\ -DgroupId =包名-DartifactId =項目名稱

我需要在模仿...- DarchetypeArtifactId = Maven的原型 - web應用程序的創建自定義原型的artifactId ...我看到上面的命令,如果是這樣,怎麼樣?

或者它僅僅是由該原型設置的文件系統的功能?我看到,我已經產生(webapp1)項目......

 
webapp1 
|-- src 
| `-- main 
|  |-- java 
|  |-- resources 
|  `-- webapp 
|   `-- WEB-INF 
`-- target 
    `-- classes` 

...比一個使用Maven的原型 - web應用產生不同的內容,但我不知道如何強制mvn eclipse:clean eclipse:eclipse來生成它(或者這是否告訴Eclipse這是一個Web應用程序,它應該設置爲Run As - > Run on Server)。

 
simpleWeb 
|-- src 
| `-- main 
|  |-- java 
|  | `-- com 
|  |  `-- mytutorial 
|  |-- resources 
|  | `-- com 
|  |  `-- mytutorial 
|  `-- webapp 
|   |-- META-INF 
|   |-- pages 
|   `-- WEB-INF 
`-- target 
    |-- classes 
    | `-- com 
    |  `-- mytutorial 
    |-- maven-archiver 
    |-- META-INF 
    | `-- maven 
    |  `-- com.mytutorial 
    |   `-- simpleWeb 
    |-- pages 
    |-- simpleWeb 
    | |-- META-INF 
    | |-- pages 
    | `-- WEB-INF 
    |  |-- classes 
    |  | `-- com 
    |  |  `-- mytutorial 
    |  `-- lib 
    |-- surefire 
    |-- test-classes 
    `-- WEB-INF 
     |-- classes 
     | `-- com 
     |  `-- mytutorial 
     `-- lib 

感謝任何能夠啓迪我的啓蒙之路的人。

Russ

P.S.這裏是我的的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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.etretatlogiciels.webapp1</groupId> 
    <artifactId>webapp1</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>webapp1 Maven Webapp</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <commons-beanutils-version> 1.8.3  </commons-beanutils-version> 
    <commons-codec-version>  1.4   </commons-codec-version> 
    <commons-collections-version> 3.2.1  </commons-collections-version> 
    <commons-digester-version>  2.1   </commons-digester-version> 
    <commons-discovery-version> 0.4   </commons-discovery-version> 
    <commons-logging-version>  1.1.1  </commons-logging-version> 
    <jsf-facelets-version>   1.1.15  </jsf-facelets-version> 
    <myfaces-version>    2.0.4  </myfaces-version> 
    <richfaces-version>   3.3.3.Final </richfaces-version> 
    </properties> 

    <pluginRepositories> 
    <pluginRepository> 
     <id>jboss-public-repository-group</id> 
     <name>JBoss Public Maven Repository Group</name> 
     <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url> 
     <layout>default</layout> 
     <releases> 
     <enabled>true</enabled> 
     <updatePolicy>never</updatePolicy> 
     </releases> 
     <snapshots> 
     <enabled>true</enabled> 
     <updatePolicy>never</updatePolicy> 
     </snapshots> 
    </pluginRepository> 
    </pluginRepositories> 

    <dependencies> 
    <!-- Apache Commons --> 
    <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
     <version>${commons-beanutils-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-codec</groupId> 
     <artifactId>commons-codec</artifactId> 
     <version>${commons-codec-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>${commons-collections-version}</version> 
     <optional>true</optional> 
    </dependency> 
    <dependency> 
     <groupId>commons-digester</groupId> 
     <artifactId>commons-digester</artifactId> 
     <version>${commons-digester-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-discovery</groupId> 
     <artifactId>commons-discovery</artifactId> 
     <version>${commons-discovery-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>${commons-logging-version}</version> 
    </dependency> 

    <!-- Facelets --> 
    <dependency> 
     <groupId>com.sun.facelets</groupId> 
     <artifactId>jsf-facelets</artifactId> 
     <version>${jsf-facelets-version}</version> 
    </dependency> 

    <!-- MyFaces --> 
    <dependency> 
     <groupId>org.apache.myfaces.core</groupId> 
     <artifactId>myfaces-api</artifactId> 
     <version>${myfaces-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.myfaces.core</groupId> 
     <artifactId>myfaces-impl</artifactId> 
     <version>${myfaces-version}</version> 
    </dependency> 

    <!-- RichFaces --> 
    <dependency> 
     <groupId>org.richfaces.framework</groupId> 
     <artifactId>richfaces-api-jsf2</artifactId> 
     <version>${richfaces-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.richfaces.framework</groupId> 
     <artifactId>richfaces-impl-jsf2</artifactId> 
     <version>${richfaces-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.richfaces.framework</groupId> 
     <artifactId>richfaces-ui-jsf2</artifactId> 
     <version>${richfaces-version}</version> 
    </dependency> 

    <!-- JUnit --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <finalName>webapp1</finalName> 
    <resources> 
     <resource> 
     <directory>src/main/java</directory> 
     <includes> 
      <include>**/*.java</include> 
     </includes> 
     </resource> 
     <resource> 
     <directory>src/main/resources</directory> 
     <excludes> 
      <exclude>**/*.java</exclude> 
     </excludes> 
     </resource> 
    </resources> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.0</version> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>2.0.2</version> 
     <configuration> 
     <source>1.5</source> 
     <target>1.5</target> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 

    <profiles> 
    <profile> 
     <id>richfaces</id> 
     <activation> 
     <activeByDefault>true</activeByDefault> 
     </activation> 
     <repositories> 
      <repository> 
      <id>maven2.repository</id> 
      <name>Repository for Maven by Maven</name> 
      <url>http://repo2.maven.org/maven2</url> 
      <layout>default</layout> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>always</updatePolicy> 
      </releases> 
      </repository> 
      <repository> 
      <id>maven2-repository.dev.java.net</id> 
      <name>Java.net Repository for Maven</name> 
      <url>http://download.java.net/maven/1</url> 
      <layout>legacy</layout> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>always</updatePolicy> 
      </releases> 
      </repository> 
      <repository> 
      <id>JBoss Repository Old</id> 
      <name>Repository for Maven by JBoss</name> 
      <url>http://repository.jboss.org/maven2</url> 
      <layout>default</layout> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>always</updatePolicy> 
      </releases> 
      </repository> 
      <repository> 
      <id>JBoss Repository Nexus</id> 
      <name>Repository for Maven by JBoss</name> 
      <url>http://repository.jboss.org/nexus/content/groups/public-jboss</url> 
      <layout>default</layout> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>always</updatePolicy> 
      </releases> 
     </repository> 
     </repositories> 
    </profile> 
    </profiles> 

</project> 
+0

什麼是你的目標是一個網絡能項目?你對問題的描述太複雜。如果你想在apache tomcat運行你的戰爭,你可以在eclipse中添加apache tomcat服務器:window-> show view-> others-> server-> servers。然後將你的項目鏈接到tomcat(我使用文件同步 - 但我的方式不是最簡單的)。 – 2011-03-24 13:52:56

+0

謝謝。我想我不知道我想要什麼,因爲我不知道Maven和Eclipse之間的空間。我的目標是通過理解來彌合這個空間,然後爲其他人撰寫(另外實際上是創建一個Web應用程序)。我的工作區中已經有了一個Tomcat服務器,但通常通過創建動態Web項目來處理Eclipse線路,這必須完成。當我讓Maven創建項目時,沒有任何接線工作正在完成。我已經將我的POM與其他POM進行了比較,這些POM似乎可以正常工作,並且無法發現差異。 – 2011-03-24 14:58:45

回答

7

我有完全相同的問題。現有的原型都不符合我的需求。如果我從自定義原型創建(來自eclipse)項目,它不會成爲動態Web項目。 如果你運行mvn -Dwtpversion = 2.0 eclipse:eclipse再次添加你不需要的各種東西。因此經過調查我終於找到了什麼可以防範「動態網站項目」。這是一組目錄和.settings目錄中的文件以及.project中的條目。

所以你需要做的是以下幾點:
1.)在eclipse中創建一個空的(非maven)動態web項目。
2.)在不添加任何文件或任何其他的變化,檢查在文件系統中通過蝕(相對於項目目錄創建下列文件):
的.project
.settings/org.eclipse.jdt.core。首選項
.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
.settings/org.eclipse.wst.jsdt.ui.superType.name
.settings/org.eclipse。 jst.jsp.core.prefs
.settings/org.eclipse.wst.common.project.facet.core.xml的
.settings/org.eclipse.wst.common.component
.settings/org.eclipse.wst.jsdt.ui.superType.container

3)這些文件到您的原型資源目錄複製您的自定義archetime
4)編輯和推廣複製的文件(更換使用$ {}的artifactId等實際項目名稱...
5)在您的原型-metadata.xml文件添加:

<fileSet encoding="UTF-8" filtered="true"> 
    <directory></directory> 
<includes> 
    <include>.project</include> 
</includes> 
</fileSet> 
<fileSet encoding="UTF-8" filtered="true"> 
    <directory>.settings</directory> 
</fileSet> 

沒有這個Maven將不能上傳文件開頭

「*」。

6.)Voila !.安裝並部署您的原型,然後重試。它爲我工作。

+0

超級!非常感謝,我的朋友! – 2011-11-30 22:55:55

1

要創建動態Web項目的Eclipse,你需要這樣做:

MVN:

1)使用類似生成項目archetype:generate>可選參數,如-Dfilter = webapp-j2ee <

這將有助於你在交互模式下生成一個Maven項目,你不必輸入artifactId,groupId等選項。

注意:它仍然可能不是動態Web項目,在我的情況下,它永遠不是.. (我想基本上它取決於你使用過的archetype-artifactId,並且我還沒有找到一個能夠自動生成動態Web模塊的基本j2ee應用程序,它只使用jsp,servlet等等)

2)現在以產生用於蝕項目文件中,使用這個命令:

MVN -Dwtpversion = 2。0 eclipse:eclipse

這將生成一個項目文件,它將設置所需的項目構面。所以當你在Eclipse IDE中導入它時,它將是一個「動態Web模塊」。

注意:現在如果您正在尋找特定版本的「Dynamic Web Module」,那麼您需要配置您的POM。版本取決於你的build標籤中以下標記:

<code> 
<build> 
...... 
    <plugins> 
    ........ 
    <plugin> 
     <groupId>   org.apache.maven.plugins </groupId> 
     <artifactId>  maven-compiler-plugin  </artifactId> 
     <version>   2.3.2      </version> 
     <configuration> 
        <source> 1.6  </source> 
        <target> 1.6  </target> 
     </configuration> 
    </plugin> 
    ......... 
    </plugins> 
....... 
</build> 
</code> 

現在,如果源和目標(在這種情況下等)設定爲1.6,則動態Web模塊2.5將得到選擇。否則,編譯器插件1.4將爲2.4,依此類推。

7

如何在你的archetype-resources/pom.xml中配置maven-eclipse-plugin?

<build> 
    <finalName>archetype-javaee5-webapp</finalName> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-eclipse-plugin</artifactId> 
       <version>2.9</version> 
       <configuration> 
        <wtpversion>2.0</wtpversion> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build>  

這將在Eclipse中創建

+1

我感謝你的迴應。最終,我放棄了常青藤+螞蟻的Maven。我知道在一個完全Maven的世界中承認這是一種詛咒,但是希望警察不會找到我;-)如果我有機會回到我的決定,我會嘗試這個解決方案。 – 2012-03-29 20:43:58

+0

這是我用來在Eclipse中將我的Web應用程序識別爲這樣的解決方案。按預期工作。 – 2012-04-13 16:39:01

+0

確保你安裝了Maven Integration for Eclipse WTP(m2e-wtp) http://marketplace.eclipse.org/node/441371#.URhKr1qje1k – Ring 2013-02-11 01:38:07

相關問題