jersey_No WebApplication provider is present

用eclipse體驗jersey框架~

首先,新建一個maven項目

選擇Jersey原型(archeTypes)



如果maven插件中沒有Jersey原型,可以遠程加載,方法如下:
目錄(catalogs)文件地址:http://repo1.maven.org/maven2/archetype-catalog.xml


生成之後的代碼結構如圖所示:



不用手動添加代碼就生成包含啓動小程序(main.java)的項目,run as java application 後,報異常:

運行項目

<span style="font-family:Microsoft YaHei;font-size:14px;">四月 18, 2016 1:37:15 下午 com.sun.jersey.api.core.PackagesResourceConfig init
信息: Scanning for root resource and provider classes in the packages:
  com.test1.JerseyTest1
四月 18, 2016 1:37:15 下午 com.sun.jersey.api.core.ScanningResourceConfig logClasses
信息: Root resource classes found:
  class com.test1.JerseyTest1.MyResource
四月 18, 2016 1:37:15 下午 com.sun.jersey.api.core.ScanningResourceConfig init
信息: No provider classes found.
Starting grizzly2...
Exception in thread "main" com.sun.jersey.api.container.ContainerException: No WebApplication provider is present
	at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69)
	at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:160)
	at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134)
	at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:243)
	at com.test1.JerseyTest1.Main.startServer(Main.java:38)
	at com.test1.JerseyTest1.Main.main(Main.java:43)</span>

註釋:選擇jersey-quickstart-grizzy或者jersey-quickstart-grizzy2原型,都報改異常

pom.xml,其中jersey-grizzly2和jersey-client是上撥雲劍查的版本號,求解
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test1</groupId>
    <artifactId>JerseyTest1</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>JerseyTest1</name>
    <dependencies>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-grizzly2</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.18</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <inherited>true</inherited>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.test1.JerseyTest1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <jersey-version>1.20-SNAPSHOT</jersey-version>
    </properties>
</project>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章