我创建了一个示例 resteasy 应用程序 Web 服务是这样的:
package com.mycompany.mavenproject1;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/")
public class HelloService {
@GET
@Path("/Hello/{name}")
public Response printMessage(@PathParam("name") String name) {
return Response.status(200).entity("Hello " + name).build();
}
}
pom.xml
<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.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>mavenproject1 Java EE 6 Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs-all</artifactId>
<version>2.2.1.GA</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
<finalName>mavenproject1</finalName>
</build>
<profiles>
<profile>
<id>endorsed</id>
<activation>
<property>
<name>sun.boot.class.path</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<!-- javaee6 contains upgrades of APIs contained within the JDK itself.
As such these need to be placed on the bootclasspath, rather than classpath of the
compiler.
If you don't make use of these new updated API, you can delete the profile.
On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.-->
<compilerArguments>
<bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<netbeans.hint.deploy.server>JBoss4</netbeans.hint.deploy.server>
</properties>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/</param-value>
</context-param>
<servlet>
<servlet-name>HelloService</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet-mapping>
<servlet-name>HelloService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
resteasy 2.2.1GA,jboss-as-disstribution-6.1.0-final,netbeans 7.0.1
请告诉我是否缺少任何部分?我是新手。请帮我..
netbeans中的输出:
cd C:\Users\admin\Desktop\mavenproject1; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_23" "\"C:\\Program Files\\NetBeans 7.0.1\\java\\maven\\bin\\mvn.bat\"" -Dnetbeans.deploy=true package
Scanning for projects...
------------------------------------------------------------------------
Building mavenproject1 Java EE 6 Webapp 1.0-SNAPSHOT
------------------------------------------------------------------------
[resources:resources]
Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
Copying 0 resource
[compiler:compile]
Compiling 1 source file to C:\Users\admin\Desktop\mavenproject1\target\classes
[resources:testResources]
Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory C:\Users\admin\Desktop\mavenproject1\src\test\resources
[compiler:testCompile]
Nothing to compile - all classes are up to date
[surefire:test]
No tests to run.
Surefire report directory: C:\Users\admin\Desktop\mavenproject1\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[war:war]
Packaging webapp
Assembling webapp[mavenproject1] in [C:\Users\admin\Desktop\mavenproject1\target\mavenproject1]
Processing war project
Copying webapp resources[C:\Users\admin\Desktop\mavenproject1\src\main\webapp]
Webapp assembled in [90 msecs]
Building war: C:\Users\admin\Desktop\mavenproject1\target\mavenproject1.war
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 2.961s
Finished at: Sun Jun 17 17:09:09 IST 2012
Final Memory: 8M/19M
------------------------------------------------------------------------
NetBeans: Deploying on JBoss Application Server
profile mode: false
debug mode: false
force redeploy: true
Distributing C:\Users\admin\Desktop\mavenproject1\target\mavenproject1.war to [org.jboss.deployment.spi.LocalhostTarget@1e8a877]
Deploying C:\Users\admin\Desktop\mavenproject1\target\mavenproject1.war
Failed
The module has not been deployed.
at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:210)
at org.netbeans.modules.maven.j2ee.ExecutionChecker.performDeploy(ExecutionChecker.java:173)
at org.netbeans.modules.maven.j2ee.ExecutionChecker.executionResult(ExecutionChecker.java:125)
at org.netbeans.modules.maven.execute.MavenCommandLineExecutor.run(MavenCommandLineExecutor.java:202)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)