Webjar无法在vert.x应用程序上工作

时间:2019-03-29 10:31:32

标签: vert.x webjars

在vert.x应用程序中配置webjar的正确方法是什么?我有一个简单的应用程序:

class WebVerticle : CoroutineVerticle() {

  override suspend fun start() {
    val router = Router.router(vertx)

    // Serve static resources from the /assets directory
    router.route("/").handler(StaticHandler.create())

    val json = ConfigRetriever.create(vertx).getConfigAwait()
    val port = json.getInteger("port")
    try {
      vertx.createHttpServer().requestHandler(router).listenAwait(port)
      println("HTTP server started on port $port - redeploy enabled")
    } catch (ex: Exception) {
      error("Could not spawn web server at port $port")
    }
  }
}

pom.xml

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-web</artifactId>
    <version>${vertx.version}</version>
</dependency>
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>vue</artifactId>
    <version>2.5.16</version>
</dependency>
</dependencies>
<build>
<plugins>
    <plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>vertx-maven-plugin</artifactId>
    <version>1.0.13</version>
    <executions>
        <execution>
        <id>vmp</id>
        <goals>
            <goal>package</goal>
            <goal>initialize</goal>
        </goals>
        </execution>
    </executions>
    <configuration>
        <redeploy>true</redeploy>
    </configuration>
    </plugin>
</plugins>
</build>

文件结构如下:

src/main/resources/webroot
| index.html

当我按下localhost:8888时,它起作用了,但是localhost:8888/vue/vue.js却没有。 还有什么我需要配置的吗?

1 个答案:

答案 0 :(得分:0)

将路由器配置更改为:

router.route().handler(StaticHandler.create("META-INF/resources"))

然后将浏览器指向:

http://localhost:8888/webjars/vue/2.5.16/vue.js