我在 os x 机器上安装了 maven:
$ mvn --version
Apache Maven 3.2.3
Java version: 1.8.0_25,
vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.1", arch: "x86_64", family: "mac"
我已经尝试了几个教程,在 SO 中环顾四周:
但是我无法设置一个可在 jetty maven 插件上运行的工作 Vaadin 项目。我的问题是在 jetty 网络服务器上找不到该项目,我总是收到 404 Not Found 错误。
以下是我所做的步骤:
$ cd ~
$ mkdir Maven
$ cd Maven
$ mvn archetype:generate \
-DarchetypeGroupId=com.vaadin \
-DarchetypeArtifactId=vaadin-archetype-application \
-DarchetypeVersion=7.3.9 \
-Dpackaging=war
...
[INFO] Archetype repository missing. Using the one from [com.vaadin:vaadin-archetype-application:7.3.9] found in catalog remote
Define value for property 'groupId': : com.example
Define value for property 'artifactId': : hello-world
Define value for property 'version': 1.0-SNAPSHOT: : 1.0
Define value for property 'package': com.example: :
[INFO] Using property: themeName = mytheme
[INFO] Using property: uiName = MyUI
[INFO] Using property: widgetsetName = MyAppWidgetset
Confirm properties configuration:
groupId: com.example
artifactId: hello-world
version: 1.0
package: com.example
themeName: mytheme
uiName: MyUI
widgetsetName: MyAppWidgetset
Y: : Y
...
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56.332 s
[INFO] Finished at: 2015-01-27T12:03:42+03:00
[INFO] Final Memory: 15M/245M
[INFO] ------------------------------------------------------------------------
$ cd hello-world
$ mvn package
...
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:00 min
[INFO] Finished at: 2015-01-27T12:08:56+03:00
[INFO] Final Memory: 21M/247M
[INFO] ------------------------------------------------------------------------
$
然后我输入 mvn jetty :运行命令:
$ mvn jetty:run
这给出了这个错误:
Maven:在当前项目中找不到前缀“jetty”的插件
所以我在 ~/.m2 目录中添加了一个 settings.xml 文件:
~/.m2/settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
</settings>
并输入 mvn jetty :运行再次:
$ mvn jetty:run
...
[INFO] Configuring Jetty for project: hello-world-parent
[INFO] webAppSourceDirectory not set. Defaulting to /Users/me/Maven/hello-world/src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes directory /Users/me/Maven/hello-world/target/classes does not exist
[INFO] Context path = /
[INFO] Tmp directory = /Users/me/Maven/hello-world/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = null
[INFO] Webapp directory = /Users/me/Maven/hello-world/src/main/webapp
2015-01-27 12:11:28.610:INFO:oejs.Server:jetty-8.1.16.v20140903
2015-01-27 12:11:29.121:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one.
2015-01-27 12:11:31.038:WARN:oejsh.RequestLogHandler:!RequestLog
2015-01-27 12:11:31.155:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server
现在你可以看到 jetty 启动了,但是当我在 打开浏览器时http://localhost:8080/ ,我得到一个 404 未找到:
Problem accessing /. Reason: Not Found
.我尝试过以下 URL 之一:没有人为我工作(我总是找不到 404)。
现在,为什么他们在文档中说如果您按照我上面所做的步骤进行操作:
瓦丁之书:
You can then open it in a web browser at http://localhost:8080/project-name.
project-name 是给 maven generate 目标的 artifactId 参数,我的是
artifactId: hello-world
,但正如我所说的 http://localhost:8080/hello-world对我不起作用(未找到 404)。我也在阅读 Vaadin 7 CookBook,他们在这里说:
We are done and we can run our new web application. Go to the root of the project where pom.xml file is located and run the following command. mvn jetty:start The application will be running on http://localhost:8080
什么???
http://localhost:8080
没有“项目名称”后缀???我已经尝试过了,但我仍然找不到404,无论如何......那么请问,是否有人可以向我解释发生了什么以及如何解决这个令人沮丧的问题,以便最终开始使用 Vaadin 进行开发?
感谢您的关注。
最佳答案
我猜你遇到了一个问题,说明是针对旧原型(prototype)版本的,其中原型(prototype)在一个月左右前更新到新版本,但说明谈论的是旧版本。最大的不同是原型(prototype)被制作成一个多模块项目,而旧的原型(prototype)是一个单模块项目。
许多人在使用多模块项目时遇到了问题,因此当前的原型(prototype)可能会在不久的将来重命名为其他东西,并且在当前的命名空间中,相同的项目将被简化为单个模块项目,以使其更容易开始和。然而,在那之前,您必须学习使用多模块项目。
如果您查看文件夹内部,您应该在 hello-world 文件夹中有一组文件夹。每个文件夹都有一个模块:
首先你应该删除你添加到 settings.xml 的东西。 Jetty 应该在应该使用它的项目的 pom.xml 中定义。现在您在全局范围内定义了它,以便它适用于所有项目,也适用于那些不能在 Jetty 上运行的项目。
为了能够运行该软件,您必须做两件事,构建整个软件并启动 -ui 模块。
mvn install
时,就会进行构建。在根文件夹中。您也可以只在 -widgetset 文件夹中执行此操作,但重要的是 -widgetset 已构建并安装到您的本地 maven 存储库中,以便 -ui 可以在需要时找到它。调用mvn install
在 root 上将导致它以正确的顺序被单独调用到所有子模块。 mvn jetty:run
来启动 UI . -ui 项目中的 pom.xml 已经定义了一个 jetty 依赖。 关于 URL 中的项目名称后缀。由 servlet 容器(Jetty 是其中之一,Tomcat、Wildfly 等是其他容器)决定是否将其部署在特定的 URL 下。 Jetty 是一个简单的 servlet 容器,您可以在需要时为项目启动它,因此
http://localhost:8080/
很好。 Tomcat等比较大,比较适合生产环境,一个Tomcat实例可以同时部署多个项目(wars),所以需要在url中加上项目名称,hello-world-ui
关于maven - 如何使用 Maven 设置工作的 Vaadin 项目并使用 Jetty 运行它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28167014/