如何为 Eclipse 创建 Web 应用程序 Maven 原型?
我有一个工作或大部分工作的 POM,它可以获取我感兴趣的所有 JAR,以编写 Facelets 应用程序。我正在使用 m2eclipse。当我导入新创建的 Maven 应用程序时,它会干净地出现,或多或少符合预期,但是,它不像动态 Web 项目,因为当我尝试运行它时,它不提供运行方式 -> 。在服务器上运行选项。
我研究了其他 Maven 生成的 Eclipse 项目,它们确实可以工作(但没有使用我想要的 JAR 组合来设置),因为它们可以在服务器上运行。例如,这个可以工作,但它没有我想要的 JAR:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp \ -DgroupId=程序包名称 -DartifactId=项目名称
我是否需要创建一个模仿 ...-DarchetypeArtifactId=maven-archetype-webapp... 我在中看到的自定义原型artifactId上面的命令,如果是的话,怎么做?
或者它仅仅是该原型设置的文件系统的一个功能?我看到我生成的项目 (webapp1)...
webapp1 |-- src | `-- main | |-- java | |-- resources | `-- webapp | `-- WEB-INF `-- target `-- classes`
... 与使用 maven-archetype-webapp 生成的内容不同,但我不知道如何强制 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
非常感谢任何能让我走上启蒙之路的人。
拉斯
这是我的 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>
I have a working or mostly working POM that fetches all and exactly just the JARs that interest me for writing a Facelets application. I'm using m2eclipse. When I import the newly Maven-created application, it comes in cleanly and more or less as expected, however, it is not like a Dynamic Web Project in that when I try to run it, it offers no Run As -> Run on Server option.
I have studied other Maven-generated Eclipse projects that do work (but don't come set up with the JAR combination I want) in the sense that they can be run on Server. For example, this one works, but it's not got the JARs I want:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp \
-DgroupId=package-name -DartifactId=project-name
Do I need to create a custom archetype artifactId in imitation of the ...-DarchetypeArtifactId=maven-archetype-webapp... I see in in the command above and, if so, how?
Or is it merely a function of the filesystem set up by that archetype? I see that the project I've generated (webapp1)...
webapp1 |-- src | `-- main | |-- java | |-- resources | `-- webapp | `-- WEB-INF `-- target `-- classes`
... has different content than one generated using maven-archetype-webapp, but I don't know how to force mvn eclipse:clean eclipse:eclipse to generate that (or whether that's what's telling Eclipse this is a web application and it should set up for 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
Profuse thanks to anyone who can launch me on the path of enlightenment.
Russ
P.S. Here's my 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也遇到过同样的问题。现有的原型都不符合我的需求。如果我从自定义原型创建(从 Eclipse)一个项目,它不会成为动态 Web 项目。
如果您运行 mvn -Dwtpversion=2.0 eclipse:eclipse 它会再次添加您不需要的各种内容。
因此,经过调查,我最终找到了“动态网络项目”的定义。它是 .settings 目录中的一堆目录和文件以及 .project 中的条目。
因此,您需要执行以下操作:
1.) 从 eclipse 中创建一个空的(非 Maven)动态 Web 项目。
2.) 在不添加任何文件或任何其他更改的情况下,在文件系统上检查 eclipse 创建的以下文件(相对于项目目录):
.项目
.settings/org.eclipse.jdt.core.prefs
.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.) 将这些文件复制到自定义原型的原型资源目录
4.) 编辑并概括复制的文件(用 ${artifactId} 等替换实际项目名称...
5.) 在您的 archetype-metadata.xml 文件中添加:
如果没有这个 maven 将不会上传以“.*”开头的文件
6.) 瞧!安装并部署您的原型,然后重试。这对我有用。
I've had exactly the same problem. None of existing archetypes matched my needs. If I created (from eclipse) a project from custom archetype it wouldn't become dynamic web project.
If you run mvn -Dwtpversion=2.0 eclipse:eclipse it again adds all sorts of things you don't need.
So after investigating I eventually found out what defeines "dynamic web project". It's a bunch of directories and files of in .settings directory and entries in .project.
So what you need to do is the following:
1.) create an empty (non-maven) dynamic web project from within eclipse.
2.) Without adding any files or any other changes, inspect on the file system the following files created by eclipse (relative to the project directory):
.project
.settings/org.eclipse.jdt.core.prefs
.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.) Copy these files to your archetype-resources directory for your custom archetime
4.) Edit and generalise the copied files (replacing actual project names with ${artifactId} etc...
5.) In your archetype-metadata.xml file add:
Without this maven will not upload files starting with ".*"
6.) Voila!. Install and deploy your archetype and try again. It worked for me.
在 archetype-resources/pom.xml 中配置 maven-eclipse-plugin 怎么样?
这将在 Eclipse 中创建一个可上网的项目
how about just configuring maven-eclipse-plugin in your archetype-resources/pom.xml?
this will create a web-able project in eclipse
要为 Eclipse 创建动态 Web 项目,您需要执行以下操作:
1) 使用以下内容生成项目:
这将帮助您以交互模式生成 Maven 项目,并且您不必输入 artifactId、groupId 等选项。
注意:它仍然可能不是动态 Web 项目,就我而言,它永远不会...
(我想基本上这取决于您使用的 archetype-artifactId,但我还没有找到一个可以为基本的 j2ee 应用程序生成动态 Web 模块的模块,该应用程序仅使用 jsp、servlet 等)
2)现在要生成 Eclipse 的项目文件,请使用以下命令:
这将生成一个项目文件,其中将设置所需的项目方面。因此,当您将其导入 Eclipse IDE 时,它将是一个“动态 Web 模块”。
注意:现在,如果您正在寻找特定版本的“动态 Web 模块”,那么您需要配置您的 POM。该版本取决于构建标记中的以下标记:
现在,如果源和目标设置为 1.6(如本例所示),则将选择 Dynamic Web Module 2.5。否则,编译器插件 1.4 的版本将为 2.4,依此类推。
To create a Dynamic Web Project for Eclipse, you need to do this :
1) generate a project using something like :
This will help you in generating a maven project in interactive mode and you won't have to type in options for artifactId, groupId etc.
Note: It still might not be a Dynamic Web Project, in my case, it never is...
(I guess basically it depends upon the archetype-artifactId that you have used and I haven't found the one which will generate a Dynamic Web module by itself for a basic j2ee app which will use only jsp's, servlet's and nothing more)
2) Now to generate the project file for eclipse, use this command:
This will generate a project file which will have the required project facet set. So when you import it in your Eclipse IDE, it will be a "Dynamic Web Module".
Note: Now if you are looking for a particular version of the "Dynamic Web Module" then you need to configure your POM. The version depends upon following tag within your build tag:
Now, if the source and target are set to 1.6 (like in this case) then the Dynamic Web Module 2.5 will get selected. Otherwise, it will be 2.4 for compiler-plugin 1.4 and so on.