Collosus Hello World示例

时间:2016-09-19 12:25:58

标签: scala maven colossus

我想使用Colossus制作REST服务器。但是我在运行此处显示的问候世界示例时遇到了困难http://tumblr.github.io/colossus/docs/quickstart/

我想使用maven,所以我创建了一个maven项目。这是我的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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>deneme</groupId>
  <artifactId>deneme</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
            <groupId>com.google.code.sbt-compiler-maven-plugin</groupId>
            <artifactId>sbt-compiler-maven-plugin</artifactId>
            <version>1.0.0-beta9</version>
            <executions>
                <execution>
                    <id>default-sbt-compile</id>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
    <groupId>com.tumblr</groupId>
    <artifactId>colossus-metrics_2.10</artifactId>
    <version>0.8.1</version>
    </dependency>
</dependency>
  </dependencies>
</project>

正如您所看到的,我包含了Colossus的依赖项。但是在下面的代码中,我在构建未找到的内容时遇到错误:object core。除了巨像之外,其他导入语句也有类似的错误。

import colossus._
import core._
import service._
import protocols.http._
import UrlParsing._
import HttpMethod._

class HelloService(context: ServerContext) extends HttpService(context) {
  def handle = {
    case request @ Get on Root / "hello" => {
      Callback.successful(request.ok("Hello World!"))
    }
  }
}

class HelloInitializer(worker: WorkerRef) extends Initializer(worker) {

  def onConnect = context => new HelloService(context)

}


object Main extends App {

  implicit val io = IOSystem()

  Server.start("hello-world", 9000){ worker => new HelloInitializer(worker) }

}

我得到的错误如下:

Compiling 1 Scala source to /bighome/saygin/workspace/deneme/target/classes...
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:2: not found: object core
[ERROR] import core._
[ERROR]        ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:3: not found: object service
[ERROR] import service._
[ERROR]        ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:4: not found: object protocols
[ERROR] import protocols.http._
[ERROR]        ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:5: not found: object UrlParsing
[ERROR] import UrlParsing._
[ERROR]        ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:6: not found: object HttpMethod
[ERROR] import HttpMethod._
[ERROR]        ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:8: not found: type HttpService
[ERROR] class HelloService(context: ServerContext) extends HttpService(context) {
[ERROR]                                                    ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:8: not found: type ServerContext
[ERROR] class HelloService(context: ServerContext) extends HttpService(context) {
[ERROR]                             ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:9: missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: ?
[ERROR]   def handle = {
[ERROR]                ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:10: not found: value on
[ERROR]     case request @ Get on Root / "hello" => {
[ERROR]                        ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:10: not found: value Get
[ERROR]     case request @ Get on Root / "hello" => {
[ERROR]                    ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:10: not found: value /
[ERROR]     case request @ Get on Root / "hello" => {
[ERROR]                                ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:10: not found: value Root
[ERROR]     case request @ Get on Root / "hello" => {
[ERROR]                           ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:11: not found: value Callback
[ERROR]       Callback.successful(request.ok("Hello World!"))
[ERROR]       ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:16: not found: type Initializer
[ERROR] class HelloInitializer(worker: WorkerRef) extends Initializer(worker) {
[ERROR]                                                   ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:16: not found: type WorkerRef
[ERROR] class HelloInitializer(worker: WorkerRef) extends Initializer(worker) {
[ERROR]                                ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:25: not found: value IOSystem
[ERROR]   implicit val io = IOSystem()
[ERROR]                     ^
[ERROR] /bighome/saygin/workspace/deneme/src/myapp.scala:27: not found: value Server
[ERROR]   Server.start("hello-world", 9000){ worker => new HelloInitializer(worker) }
[ERROR]   ^
[ERROR] 17 errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45:26 min
[INFO] Finished at: 2016-09-19T13:50:18+03:00
[INFO] Final Memory: 24M/514M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.code.sbt-compiler-maven-plugin:sbt-compiler-maven-plugin:1.0.0-beta9:compile (default-sbt-compile) on project deneme: Scala compilation failed: CompileFailed -> [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/MojoFailureException

我该怎么办?

1 个答案:

答案 0 :(得分:4)

看起来你只是添加了colossus-metrics_2.10作为依赖,但实际上它并没有依赖巨人本身,所以你实际上并没有吸引巨人。

我没有尝试重现自己,但我认为如果你为colossus_2.10添加另一个依赖项,它应该解决问题。