I'm trying to set up a service with Payara Micro (5.191) and xsbt-web-plugin (4.0.2).
build.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
}
}
Hello.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
}
}
The server starts and shows no errors, but I can not open the web site.
1) Is http://localhost:8080/test the right URL?
2) How can I check if this application is deployed?
3) What did I miss?
With help from earldouglas (many thanks for that), I got it running:
Project files:
/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: like in the question above, but remove the second GET-request. Two equal requests on the same endpoint don't work.
Main.scala: see above
web.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: like above, but replace lines
containerLaunchCmd in Container := { (port, path) =>
Seq("fish.payara.micro.PayaraMicro")
}
with
containerLaunchCmd in Container := { (port, path) =>
Seq("fish.payara.micro.PayaraMicro", "--deploy", "target/webapp", "--contextroot", "/")
}
and also change the project val to
lazy val testService = (project in file("."))
maybe you want to change contextroot depending on your needs.
With every source change you need to run container:start
.
After payara micro is started, you can check it:
curl localhost:8080/hello
curl localhost:8080/application.wadl
UPDATE the files are available as example project at
https://github.com/earldouglas/xsbt-web-plugin/tree/master/docs/examples/payara-micro