Rest 使用maven时出现编译错误:";“源代码1.3”中不支持注释;

Rest 使用maven时出现编译错误:";“源代码1.3”中不支持注释;,rest,maven,Rest,Maven,我使用Eclipse创建了一个RESTfulWeb服务简单项目。当我试图编译它时,我得到以下错误 <dependencies> <dependency> <groupId>jersey-server</groupId> <artifactId>jersey-server</artifactId> <version>1.4</version> <scope>

我使用Eclipse创建了一个RESTfulWeb服务简单项目。当我试图编译它时,我得到以下错误

<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>
不确定为什么不支持注释,我使用NetBeans IDE做了同样的事情,
它运行良好,没有任何问题

**[INFO] Compilation failure
C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:[18,1] error: annotations are not supported in -source 1.3
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.BuildFailureException: Compilation failure
C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:[18,1] error: annotations are not supported in -source 1.3
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:[18,1] error: annotations are not supported** in -source 1.3
<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>
这是我的pom文件结构:

<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>
POM文件

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>RestfulService</groupId>
  <artifactId>RestfulService</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>${basedir}/src</sourceDirectory>
    <outputDirectory>${basedir}/build/classes</outputDirectory>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
</pluginManagement>

</build>

<dependencyManagement>
<dependencies>

  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

<dependency>
        <groupId>javax-ws</groupId>
        <artifactId>javax-ws</artifactId>
        <version>1.4</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
</dependency>
</dependencies>
</dependencyManagement>
</project>
<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>

4.0.0
休息服务
休息服务
0.0.1-快照
${basedir}/src
${basedir}/build/classes
org.apache.maven.plugins
maven编译器插件
3
1.6
1.6
泽西服务器
泽西服务器
1.4
系统
${basedir}/lib/jersey-server-1.4.jar
javax-ws
javax-ws
1.4
系统
${basedir}/lib/javax.ws.rs.jar
Hello.java

package restfu;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

// Plain old Java Object it does not extend as class or implements 
// an interface

// The class registers its methods for the HTTP GET request using the @GET annotation. 
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML. 

// The browser requests per default the HTML MIME type.

//Sets the path to base URL + /hello
@Path("/hello")
public class Hello {

  // This method is called if TEXT_PLAIN is request
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayPlainTextHello() {
    return "Hello Jersey";
  }

  // This method is called if XML is request
  @GET
  //@Produces(MediaType.TEXT_XML)
  @Produces("application/xml")
  public String sayXMLHello() {
    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
  }

  // This method is called if HTML is request
  @GET
  @Produces(MediaType.TEXT_HTML)
  public String sayHtmlHello() {
    return "<html> " + "<title>" + "Hello Jersey" + "</title>"
        + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
  }

  // This method is called if JSON is request
  @GET
  //@Produces("appplication/json")
  @Produces(MediaType.APPLICATION_JSON)
  public String sayJsonHello() {
    return "{ \"HTML\": { \"title\": \"Hello Jersey\", \"body\": { \"h1\": \"Hello Jersey\" }}" ;
  }    
} 
<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>
package-restfu;
导入javax.ws.rs.GET;
导入javax.ws.rs.Path;
导入javax.ws.rs.products;
导入javax.ws.rs.core.MediaType;
//普通的旧Java对象,它不作为类或实现进行扩展
//接口
//该类使用@GET注释为HTTP GET请求注册其方法。
//使用@products注释,它定义了它可以传递几种MIME类型,
//文本、XML和HTML。
//浏览器默认请求HTML MIME类型。
//设置基本URL+/hello的路径
@路径(“/hello”)
公共课你好{
//如果请求文本,则调用此方法
@得到
@生成(MediaType.TEXT\u PLAIN)
公共字符串sayplantextHello(){
返回“Hello Jersey”;
}
//如果请求XML,则调用此方法
@得到
//@生成(MediaType.TEXT\u XML)
@生成(“应用程序/xml”)
公共字符串sayXMLHello(){
返回“+”Hello Jersey“+”;
}
//如果请求HTML,则调用此方法
@得到
@生成(MediaType.TEXT\u HTML)
公共字符串sayHtmlHello(){
返回“+”+“Hello Jersey”+“
+“+”你好,泽西衫“+”+“+”;
}
//如果请求JSON,则调用此方法
@得到
//@产生(“应用程序/json”)
@产生(MediaType.APPLICATION_JSON)
公共字符串sayJsonHello(){
返回“{\“HTML\”:{\“title\”:“Hello Jersey\”,“body\”:{\“h1\”:“Hello Jersey\”});
}    
} 

通过以下几点增强您的pom:

<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>

[...]
[...]
org.apache.maven.plugins
maven编译器插件
3
1.5
1.5
[...]
[...]
你需要至少给出1.5,但最好是1.6

<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>
我建议不要更改源代码的默认位置。最好将源代码移动到maven:src/main/java的默认位置,并从pom中删除配置:

<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>

${basedir}/src
${basedir}/target/classes

插件管理
中添加java版本1.5或更高版本(如果可能,在父pom中):

<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>

org.apache.maven.plugins
maven编译器插件
3
1.5
1.5

谢谢,我在basedir中创建了lib文件夹,然后将库文件复制到其中,然后按如下方式添加依赖项,然后解决了编译问题 它创建了jar文件和类文件

<dependencies>
  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

    <dependency>
    <groupId>javax-ws</groupId>
    <artifactId>javax-ws</artifactId>
    <version>1.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
  </dependency>

泽西服务器
泽西服务器
1.4
系统
${basedir}/lib/jersey-server-1.4.jar
javax-ws
javax-ws
1.4
系统
${basedir}/lib/javax.ws.rs.jar

您使用的是哪个版本的Maven?C:\Users\gopc>mvn-版本ApacheMaven 2.2.1(r801777;2009-08-07 03:16:01+0800)Java版本:1.7.0\u 09 Java主页:C:\Program Files(x86)\Java\jdk1.7.0\jre默认区域设置:en\u-US,平台编码:Cp1252操作系统名称:“windows 7”版本:“6.1”arch:“x86”系列:“windows”将源和目标添加到1.6之后,注释编译错误消失了,但它无法解析库中外部jar的导入。例如:[error]/C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[3,19]包javax.ws.rs不存在可能您需要添加补充?补充依赖项是什么意思…我在这篇文章中发布了maven dependencies pom文件,请帮助我。。