【问题标题】:Path class from stdlib has no function "of"来自 stdlib 的路径类没有函数 \"of\"
【发布时间】:2022-07-11 05:40:03
【问题描述】:

在这段代码中,和this example一样,我尝试通过DirectoryCodeResolver配置resolver,但是它的参数Path.of(\"somePath\")不正确,没有这个功能。

Path 来自java.nio.file.Path,但没有of()。也许,某些文件定义了Path 类的扩展名?

package com.example

import io.ktor.server.engine.*
import io.ktor.server.netty.*
import com.example.plugins.*
import gg.jte.TemplateEngine
import gg.jte.resolve.DirectoryCodeResolver
import io.ktor.server.application.*
import io.ktor.server.jte.*
import java.nio.file.Path

fun main() {
    embeddedServer(Netty, port = 8080, host = \"0.0.0.0\") {
        install(Jte) {
            val resolver = DirectoryCodeResolver(Path.of(\"html\"))
            templateEngine = TemplateEngine.create(resolver, gg.jte.ContentType.Html)
        }
        configureRouting()
    }.start(wait = true)
}

    标签: kotlin ktor


    【解决方案1】:

    java.nio.file.Path 来自爪哇 11起有static Path of​(String first, String... more)方法(doc)。您可能使用的是较低的 Java 版本,因此无法在标准库中找到该方法。

    尝试升级您的 Java 版本,您应该能够使用方法 Path.of("html"),如示例中所示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      • 2020-05-15
      相关资源
      最近更新 更多