如何使用Maven创建最小的Java应用程序框架?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何使用Maven创建最小的Java应用程序框架?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3593字,纯文字阅读大概需要6分钟。
内容图文
![如何使用Maven创建最小的Java应用程序框架?](/upload/InfoBanner/zyjiaocheng/678/b22134241bee410496ac627a2b1f99b8.jpg)
这个问题已经在这里有了答案: > Maven archetype for simple Servlet application 6个
为了进行测试,我需要创建一个非常简单的Java Web应用程序,它将仅包含一个servlet.
我希望能够轻松运行该Web应用程序(例如,输入mvn jetty:run).
对于Vaadin应用程序,我使用了以下调用:
1) mvn archetype:generate
-DarchetypeGroupId=com.vaadin
-DarchetypeArtifactId=vaadin-archetype-clean
-DarchetypeVersion=LATEST
-DgroupId=your.company
-DartifactId=project-name
-Dversion=1.0
-Dpackaging=war
2) mvn eclipse:eclipse
现在,我需要类似的调用才能使用一个servlet创建一个简单的Web应用程序.
我该怎么做(我可以使用哪个Maven命令/原型)?
解
为了创建Web应用程序的框架,请执行以下步骤:
1)运行
mvn archetype:generate -DgroupId=ru.mycompany -DartifactId=mywebapp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
2)放
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>7.0.0.pre5</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
放入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>ru.mycompany</groupId>
<artifactId>mywebapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>mywebapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>mywebapp</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>7.0.0.pre5</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
3)运行mvn jetty:run -Djetty.port = PORT并确认您看到了Hello World!浏览器中的字母(localhost:PORT / mywebapp),其中PORT是您要运行Jetty的端口号.
解决方法:
您将需要使用-DarchetypeArtifactId = maven-archetype-webapp创建原型
同样对于码头:运行要工作,您需要用jetty plugin更新pom.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>7.0.0.pre5</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
内容总结
以上是互联网集市为您收集整理的如何使用Maven创建最小的Java应用程序框架?全部内容,希望文章能够帮你解决如何使用Maven创建最小的Java应用程序框架?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。