首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Payara?

如何使用Payara?
EN

Stack Overflow用户
提问于 2019-03-11 20:58:03
回答 1查看 96关注 0票数 2

我正在尝试建立一个服务与贝拉拉微(5.191)和(4.0.2)。

build.sbt:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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
  }
}

Hello.scala:

代码语言:javascript
复制
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是正确的网址吗?

2)如何检查是否部署了此应用程序?

3)我错过了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-12 18:50:57

在地球玻璃的帮助下(非常感谢),我让它运转起来:

项目档案:

代码语言:javascript
复制
/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:见上文

web.xml:

代码语言:javascript
复制
<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:和上面一样,但是替换行

代码语言:javascript
复制
containerLaunchCmd in Container := { (port, path) =>
  Seq("fish.payara.micro.PayaraMicro")
}

使用

代码语言:javascript
复制
containerLaunchCmd in Container := { (port, path) =>
  Seq("fish.payara.micro.PayaraMicro", "--deploy", "target/webapp", "--contextroot", "/")
}

,并将项目val更改为

代码语言:javascript
复制
lazy val testService = (project in file("."))

也许你想根据你的需要改变环境。

对于每个源更改,您都需要运行container:start

在payara微启动后,您可以检查它:

curl localhost:8080/hello

curl localhost:8080/application.wadl

更新文件可作为示例项目在

https://github.com/earldouglas/xsbt-web-plugin/tree/master/docs/examples/payara-micro

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55110303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档