我在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 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:找不到前缀'码头'在当前项目中
所以我在〜/ .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
现在您可以看到jetty启动,但是当我在 http://localhost:8080/ 打开浏览器时,我找不到404:Problem accessing /. Reason: Not Found
。我尝试过以下网址之一:
没有人为我工作(我总是找不到404)。
现在,为什么他们在文档中说如果你按照我上面的步骤进行操作:
瓦丁书:
然后,您可以在网络浏览器中打开它 http://localhost:8080/project-name
project-name是赋予maven生成目标的artifactId参数,我的是artifactId: hello-world
,但正如我所说http://localhost:8080/hello-world对我不起作用(404未找到)。< / p>
我也在阅读Vaadin 7 CookBook,他们在这里说:
我们已经完成,我们可以运行我们的新Web应用程序。转到。的根 pom.xml文件所在的项目并运行以下命令 命令。 mvn jetty:start应用程序将运行 http://localhost:8080
什么??? http://localhost:8080
没有&#34;项目名称&#34;后缀???我已经尝试过了,但仍然没有找到404,无论如何......
那么,有没有人可以解释我发生了什么,我怎样才能解决这个令人沮丧的问题,以便最终开始与Vaadin一起开发?
感谢您的关注。
答案 0 :(得分:8)
我猜你遇到了一个问题,那里的指令是针对一个旧的原型版本,其中原型在一个月左右的时间里被更新为一个新版本,但是说明书谈论了旧版本。最大的区别在于原型被制作成一个多模块项目,其中旧的原型是单个模块项目。
许多人在处理多模块项目时遇到了问题,因此当前的原型可能会在不久的将来重命名为其他东西,而在当前的命名空间中,同一个项目将缩减回单个模块项目以使其更容易开始使用。但是,到那时为止,您将不得不学习使用多模块项目。
如果你查看文件夹内部,你应该在hello-world文件夹中有一组文件夹。每个文件夹都有一个模块:
首先应删除添加到settings.xml的内容。应该在应该使用它的项目的pom.xml中定义Jetty。现在,您已全局定义它,以便它适用于所有项目,也适用于无法在Jetty上运行的项目。
为了能够运行软件,您必须做两件事,构建整个软件并启动-ui模块。
mvn install
时会发生构建。您也可以在-widgetset文件夹中执行此操作,但重要的是-widgetset会构建并安装到您的本地maven存储库中,以便-ui可以在需要时找到它。在root上调用mvn install
将导致以正确的顺序单独调用所有子模块。mvn jetty:run
来完成的。 -ui项目中的pom.xml定义了一个jetty依赖项。关于URL中的项目名称后缀。它取决于servlet容器(Jetty是其中之一,Tomcat,Wildfly等是其他人)来决定它是否将其部署在特定URL下。 Jetty是一个简单的servlet容器,只要你需要它就可以为项目启动,因此http://localhost:8080/
很好。 Tomcat和其他更大的更适合生产,并且您可以同时在一个Tomcat实例中部署许多项目(战争),因此需要通过将项目名称添加到URL hello-world-ui
中来将它们分开。