【发布时间】:2015-03-25 20:42:59
【问题描述】:
我在 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 中环顾四周:
- https://vaadin.com/book/-/page/getting-started.maven.html
- https://vaadin.com/wiki/-/wiki/Main/Creating+a+Maven+project
- http://www.maxpagels.com/tutorials/vaadin-tutorial/
- 404 Not Found Error in a simple Jetty/Maven Hello World webapp
但我无法设置可在 jetty maven 插件上运行的工作 Vaadin 项目。我的问题是在jetty web服务器上找不到项目,总是报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:run 命令:
$ 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:run:
$ 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
现在你可以看到码头启动了,但是当我在 http://localhost:8080/ 打开浏览器时,我得到一个 404 未找到:Problem accessing /. Reason: Not Found。我尝试过以下网址之一:
- http://localhost:8080/
- http://localhost:8080
- http://localhost:8080/hello-world
- http://localhost:8080/hello-world/
- http://localhost:8080/hello-world-parent/
- http://localhost:8080/hello-world-parent
- http://localhost:8080/webapp
- http://localhost:8080/webapp/
没有人为我工作(我总是得到 404 not found)。
现在,为什么他们在文档中说如果您按照我上面所做的步骤操作:
瓦丁之书:
然后您可以在网络浏览器中打开它 http://localhost:8080/project-name.
project-name 是赋予 maven generate 目标的 artifactId 参数,我的是 artifactId: hello-world,但正如我所说的 http://localhost:8080/hello-world 对我不起作用(404 未找到)。
我也在阅读 Vaadin 7 CookBook,他们说:
我们完成了,我们可以运行我们的新 Web 应用程序了。去到根 pom.xml文件所在的项目,运行以下 命令。 mvn jetty:start 应用程序将在 http://localhost:8080
什么??? http://localhost:8080 没有“项目名称”后缀???我已经尝试过了,但我仍然找不到 404,无论如何...
请问,有没有人可以向我解释发生了什么,我该如何解决这个令人沮丧的问题,以便最终开始使用 Vaadin 进行开发?
感谢您的关注。
【问题讨论】: