我使用jetty作为项目的嵌入部分。当我使用maven编译我的测试项目时,它会抛出以下异常:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jetty-test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jettytest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /workspaces/JettyTest/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ jettytest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- scala-maven-plugin:3.2.2:compile (default) @ jettytest ---
[INFO] /workspaces/JettyTest/src/main/scala:-1: info: compiling
[INFO] Compiling 4 source files to /workspaces/JettyTest/target/classes at 1440407546804
[WARNING] warning: Class java.nio.channels.ReadPendingException not found - continuing with a stub.
[ERROR] error: Class java.nio.channels.ReadPendingException not found - continuing with a stub.
[WARNING] warning: Class java.nio.channels.WritePendingException not found - continuing with a stub.
[ERROR] error: Class java.nio.channels.WritePendingException not found - continuing with a stub.
[WARNING] two warnings found
[ERROR] two errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.820 s
[INFO] Finished at: 2015-08-24T17:12:30+08:00
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default) on project jettytest: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
pom.xml的一部分:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.scala-lang.version>2.11.6</org.scala-lang.version>
<jettyVersion>9.3.2.v20150730</jettyVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jettyVersion}</version>
</dependency>
<!-- scala -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${org.scala-lang.version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
我的测试代码如下所示(Scala):
val server = new Server()
val connector = new ServerConnector(server)
connector.setHost("localhost")
connector.setPort(8080)
connector.setIdleTimeout(30000)
// Set a connector
server.addConnector(connector)
val context = new ContextHandler()
context.setContextPath("/")
context.setHandler(new HelloHandler())
// Set a handler
server.setHandler(context)
// Start the server
server.start()
server.join()
我发现如果我减少下面的代码,它可以编译成功。编译ServerConnector时似乎抛出异常。但错误消息似乎不是编译失败的真正原因。有人可以帮帮我吗?
val server = new Server()
val context = new ContextHandler()
context.setContextPath("/")
context.setHandler(new HelloHandler())
// Set a handler
server.setHandler(context)
// Start the server
server.start()
server.join()
$ mvn --version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: /Users/wanbo/server/maven
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: zh_CN, platform encoding: EUC_CN
OS name: "mac os x", version: "10.10.3", arch: "x86_64", family: "mac"
答案 0 :(得分:1)
听起来你没有使用Java 8进行编译。