【问题标题】:Needed help fixing the pom for a Scala application with Spray and Akka需要帮助使用 Spray 和 Akka 修复 Scala 应用程序的 pom
【发布时间】:2017-09-11 01:16:27
【问题描述】:

我正在尝试使用 Spray 和 Akka 创建一个新的 Scala 项目。我正在使用 Scala 2.12.1,我的 pom 看起来像这样。

<dependencies>
    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-actor_2.12</artifactId>
        <version>2.4.16</version>
    </dependency>

    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.12.1</version>
    </dependency>

    <dependency>
        <groupId>com.enragedginger</groupId>
        <artifactId>akka-quartz-scheduler_2.12</artifactId>
        <version>1.6.0-akka-2.4.x</version>
    </dependency>

    <dependency>
        <groupId>io.spray</groupId>
        <artifactId>spray-servlet</artifactId>
        <version>1.3.1</version>
    </dependency>

    <dependency>
        <groupId>io.spray</groupId>
        <artifactId>spray-routing</artifactId>
        <version>1.3.1</version>
    </dependency>

    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-slf4j_2.12</artifactId>
        <version>2.4.16</version>
    </dependency>

    <dependency>
        <groupId>com.typesafe.akka</groupId>
        <artifactId>akka-http-spray-json_2.12</artifactId>
        <version>10.0.5</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

    <dependency>
        <groupId>commons-dbutils</groupId>
        <artifactId>commons-dbutils</artifactId>
        <version>1.6</version>
    </dependency>


    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.9.9</version>
    </dependency>

    <dependency>
        <groupId>org.scala-lang.modules</groupId>
        <artifactId>scala-xml_2.12</artifactId>
        <version>1.0.6</version>
    </dependency>

</dependencies>

这个 pom 构建了一个 WAR 文件,但是每次我尝试将该 WAR 文件部署到服务器上时,我都会收到以下错误。我相信我使用的依赖项与 Scala 2.12.1 兼容,你们都发现有什么问题吗?

java.lang.NoClassDefFoundError: scala/Product$class
    at spray.http.Uri$Path$Empty$.<init>(Uri.scala:435)
    at spray.http.Uri$Path$Empty$.<clinit>(Uri.scala)
    at spray.http.Uri$Path$.<init>(Uri.scala:415)
    at spray.http.Uri$Path$.<clinit>(Uri.scala)
    at spray.servlet.ConnectorSettings$.fromSubConfig(ConnectorSettings.scala:52)

【问题讨论】:

  • 您是否正在构建一个包含所有依赖项的 WAR。我从未在 JVM 上使用过 WAR,我一直使用 fat jat:stackoverflow.com/questions/23089700/deploy-war-or-fat-jar
  • 是的,与所有依赖项作战。但我正在通过 intellij 部署这场战争。
  • 作为建议,您应该考虑使用与 scala 2.12.1 兼容并取代 Spray 的 akka-http

标签: scala maven akka pom.xml spray


【解决方案1】:

我认为spray-* jar 没有针对 scala 2.12 的 crossPath 构建。使用 Akka-Http 10.0.x for 2.12,它的代码与 spray-framework 的 API 几乎兼容。

另外请注意,使用异步功能相当有限的 WAR/servlet 违背了 Akka 背后的整体理念。

请同时使用 typesafe akka* jars of version 2.4.17 和 typesafe akka-http* 10.0.5 以确保版本兼容性。

【讨论】:

    猜你喜欢
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多