maven项目的启动和使用jetty:run指令

来源:互联网 发布:usm锐化算法 编辑:程序博客网 时间:2024/05/16 07:30

最近出去实习,头一次接触Maven,度过了一脸懵逼的阶段后才发现maven真是好用。刚从svn上同步下来一份代码,然后尴尬的发现不会运行, 只好搜资料,然后总结出流程如下:

run->run configeration...到达


Name随便起;在browse Workspace下面找到你的工程,然后在goals下面输入指令jetty:run

点击run

在console窗口

[INFO] Initializing Spring FrameworkServlet 'clk'
[INFO] Started SelectChannelConnector@0.0.0.0:8800
[INFO] Started Jetty Server

说明端口是8800

此时项目已经启动,在浏览器中输入http://localhost:8800/clkpre即可访问。


当然过程并没有这么顺,首先是使用jetty:run时候报错,报错信息如下:

config\src\main\webapp

2017-02-2810:34:06.340:INFO:oejs.Server:jetty-8.1.16.v20140903

2017-02-2810:34:07.801:INFO:oejpw.PlusConfiguration:No Transaction manager found - ifyour webapp requires one, please configure one.

2017-02-2810:34:08.543:WARN:oeja.AnnotationParser:Problem processing jar entrycom/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class

java.lang.ArrayIndexOutOfBoundsException: 48188

    atorg.objectweb.asm.ClassReader.readClass(Unknown Source)

    atorg.objectweb.asm.ClassReader.accept(Unknown Source)

    atorg.objectweb.asm.ClassReader.accept(Unknown Source)

    atorg.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:899)

    atorg.eclipse.jetty.annotations.AnnotationParser$2.processEntry(AnnotationParser.java:857)

    atorg.eclipse.jetty.webapp.JarScanner.matched(JarScanner.java:161)

    atorg.eclipse.jetty.util.PatternMatcher.matchPatterns(PatternMatcher.java:100)

    atorg.eclipse.jetty.util.PatternMatcher.match(PatternMatcher.java:82)

    at org.eclipse.jetty.webapp.JarScanner.scan(JarScanner.java:84)

.........

上网搜到也有道友报这种错误的

[ERROR] No plugin found for prefix 'jetty' in the current project and in the plu  
gin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repo  
sitories [local (C:\Documents and Settings\Administrator\.m2\repository), centra  
l (http://repo.maven.apache.org/maven2)] -> [Help 1]  
[ERROR]  
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit  

解决方法:

报错的原因是没有找到jetty插件。


这个setting.xml是我在maven的conf目录下拷贝出来的,也可以直接在conf下的setting中改,但是有个问题就是当maven升级的时候你还有备份你的配置文件,比较麻烦。打开这个文件,添加红色字体的代码,加入jetty的配置。

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
<pluginGroup>org.mortbay.jetty</pluginGroup>
  </pluginGroups>

就是在对应的pom中加入plug配置,但是太麻烦

<plugin>  
                <groupId>org.mortbay.jetty</groupId>  
                <artifactId>jetty-maven-plugin</artifactId>  
                <configuration>  
                    <webApp>  
                        <contextPath>/</contextPath>  
                    </webApp>  
                    <stopKey>webx</stopKey>  
                    <stopPort>9999</stopPort>  
                    <connectors>  
                        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">  
                            <port>8081</port>  
                            <maxIdleTime>60000</maxIdleTime>  
                        </connector>  
                    </connectors>  
                    <requestLog implementation="org.eclipse.jetty.server.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>${productionMode}</value>  
                        </systemProperty>  
                    </systemProperties>  
                </configuration>  
            </plugin>  

最后一种是goals指令直接使用mvn org.mortbay.jetty:maven-jetty-plugin:run,但是我的还是报错,所以使用了第一种方法。

0 0
原创粉丝点击