2011-03-23 106 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

相关问题