payara - 如何将 Payara Micro 与 xsbt-web-plugin 一起使用?
问题描述
我正在尝试使用 Payara Micro (5.191) 和 xsbt-web-plugin (4.0.2) 设置服务。
构建.sbt:
ThisBuild / organization := "local.test"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.12.8"
lazy val testService = project
.enablePlugins(ContainerPlugin)
.settings(
javaOptions in Container ++= Seq("-Xdebug", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"),
libraryDependencies ++= Seq(
microprofile,
servlet
),
containerLibs in Container := Seq(
"fish.payara.extras" % "payara-micro" % "5.191"
),
containerLaunchCmd in Container := { (port, path) =>
Seq("fish.payara.micro.PayaraMicro")
}
)
lazy val microprofile = {
sys.props += "packaging.type" -> "jar"
"org.eclipse.microprofile" % "microprofile" % "2.2" % "provided" pomOnly()
}
lazy val servlet = "javax.servlet" % "javax.servlet-api" % "4.0.1" % "provided"
Main.scala:
package local.test
import java.util
import javax.ws.rs.ApplicationPath
import javax.ws.rs.core.Application
import local.test.endpoint.Hello
@ApplicationPath("/*")
class Main extends Application {
override def getClasses: util.Set[Class[_]] = {
val h = new util.HashSet[Class[_]]
h.add(classOf[Hello])
h
}
}
你好.scala:
package local.test.endpoint
import javax.ws.rs.core.{MediaType,Response}
import javax.ws.rs.{GET, Path, Produces, QueryParam}
@Path("/hello")
class Hello {
@GET
@Produces(Array(MediaType.TEXT_PLAIN))
def getMessage(@QueryParam("name") name: String): Response = {
Response.ok("Hallo " + name).build
}
@GET
@Produces(Array(MediaType.TEXT_PLAIN))
def getMessage: Response = {
Response.ok("Hallo Nobody").build
}
}
服务器启动并显示没有错误,但我无法打开网站。
1) http://localhost:8080/test是正确的 URL 吗?
2) 如何检查此应用程序是否已部署?
3)我错过了什么?
解决方案
在earldouglas 的帮助下(非常感谢),我让它运行起来了:
项目文件:
/project-root
+ project/
| + build.properties (single line content: sbt.version=1.2.8)
| + plugins.sbt (single line content: addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.2") )
|
+ src/main/
| + scala/local/test/
| | + endpoint/
| | | + Hello.scala
| | + Main.scala
| + webapp/WEB-INF/
| + web.xml
|
+ build.sbt
Hello.scala:就像上面的问题一样,但删除第二个 GET 请求。同一端点上的两个相等请求不起作用。
Main.scala:见上文
网页.xml:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
build.sbt:和上面一样,但是替换行
containerLaunchCmd in Container := { (port, path) =>
Seq("fish.payara.micro.PayaraMicro")
}
和
containerLaunchCmd in Container := { (port, path) =>
Seq("fish.payara.micro.PayaraMicro", "--deploy", "target/webapp", "--contextroot", "/")
}
并将项目 val 更改为
lazy val testService = (project in file("."))
也许您想根据需要更改上下文根。
随着每次源代码更改,您需要运行container:start
.
payara micro启动后,可以查看:
curl localhost:8080/hello
curl localhost:8080/application.wadl
更新 文件可作为示例项目在
https://github.com/earldouglas/xsbt-web-plugin/tree/master/docs/examples/payara-micro
推荐阅读
- vb.net - VB.NET:将日期 dd/mm/yy 转换为 dd/mm/yyyy
- jquery - 通过“标题开头”将点击处理程序添加到元素的父级
- laravel - 如何在 eloquent Orm 中编写复杂的查询?
- javascript - indexOf() 在错误的情况下显示“-1”
- python - 包括带有 nbsphinx 的笔记本失败
- c# - Asp.Net Core 使用 Html.ActionLink 路由到区域控制器
- java - 是否可以在一个 Java 项目中集成两个 Jasper 版本?
- android - 调整drawable以适应EditText
- go - Goroutine 中关键字“go”和没有的比较
- javascript - Vue // this.$root.$off 从全局事件中取消订阅组件的所有实例