一、创建webx项目
按照网上的教程创建webx项目时,采用的命令如下:
mvn archetype:generate -DgroupId=com.alibaba.webx -DartifactId=tutorial1 -Dversion=1.0-SNAPSHOT -Dpackage=com.alibaba.webx.tutorial1 -DarchetypeArtifactId=archetype-webx-quickstart -DarchetypeGroupId=com.alibaba.citrus.sample -DarchetypeVersion=1.0 -DinteractiveMode=false
运行mvn jetty:run时,出现的错误为:
No plugin found for prefix 'jetty' in the current project and in the plugin groups [com.alibaba.org.apache.maven.plugins, com.alibaba.maven.plugins, org.apache.maven.plugins, org.codehaus.mojo] available from the repositorie
s [local (d:\mvn\repo), tbmirror-all (http://mvnrepo.alibaba-inc.com/mvn/repository)] -> [Help 1]
二、问题排查
方法一:直接查看pom.xml中,发现没有dependency的依赖,添加 之后,运行显示:
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/</contextPath>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8081</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
<filename>target/access.log</filename>
<retainDays>90</retainDays>
<append>false</append>
<extended>false</extended>
<logTimeZone>GMT+8:00</logTimeZone>
</requestLog>
<systemProperties>
<systemProperty>
<name>productionMode</name>
<value>false</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
运行显示:
Failed to execute goal org.mortbay.jetty:jetty-maven-plugin:7.0.0.pre5:run (default-cli) on project tutorial1: Webapp source directory D:\Code\tutorial1\src\main\webapp does no
t exist
8081端口也没有监听。
方法二:看别人搭建过程和我的一样,然而pom.xml自动生成了,并且有jetty依赖,且自动生成了webapp文件夹。认真对比了命令行,发现是archetype的版本号太旧了,-DarchetypeVersion=1.8,更改之后,运行正常。
三、思考
一个bug纠结了1个小时,最后发现是参考手册比较旧了,版本号有问题。参照创建项目时,又出现了文件结构不一致的问题,下次有时间将这个参考手册更新一下啊~
总结:
mvn archetype:generate 使用archetype插件自动生成
-DgroupId=com.alibaba.webx groupId和artifactId确定唯一的maven坐标
-DartifactId=tutorial1
-Dversion=1.0-SNAPSHOT
-Dpackage=com.alibaba.webx.tutorial1
-DarchetypeArtifactId=archetype-webx-quickstart archetype模板,创建webapp和自动生成pom.xml
-DarchetypeGroupId=com.alibaba.citrus.sample
-DarchetypeVersion=1.8
-DinteractiveMode=false