o-0
o-0

Reputation: 1799

Playframework [Scala]: The app cannot access its assets in production

I'm getting an error regarding accessing assets, while running my app in production (works fine on during development):

[info] play.api.Play - Application started (Prod)
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
[error] application - 

! @784kabl4n - Internal server error, for (GET) [/assets/images/favicon.png] ->

play.api.UnexpectedException: Unexpected exception[RuntimeException: java.lang.IllegalAccessError: class play.utils.Resources$ (in unnamed module @0x67dd1848) cannot access class sun.net.www.protocol.file.FileURLConnection (in module java.base) because module java.base does not export sun.net.www.protocol.file to unnamed module @0x67dd1848]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:251)
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:182)
    at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:343)
    at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:341)
    at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:414)
    at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
    at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
    at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessError: class play.utils.Resources$ (in unnamed module @0x67dd1848) cannot access class sun.net.www.protocol.file.FileURLConnection (in module java.base) because module java.base does not export sun.net.www.protocol.file to unnamed module @0x67dd1848
    at play.api.mvc.ActionBuilder$$anon$2.apply(Action.scala:424)
    at play.api.mvc.Action.$anonfun$apply$2(Action.scala:96)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$4(Accumulator.scala:174)
    at scala.util.Try$.apply(Try.scala:209)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$3(Accumulator.scala:174)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:52)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:52)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:52)
    at play.api.libs.streams.StrictAccumulator.run(Accumulator.scala:207)
    at play.core.server.AkkaHttpServer.$anonfun$runAction$4(AkkaHttpServer.scala:337)
Caused by: java.lang.IllegalAccessError: class play.utils.Resources$ (in unnamed module @0x67dd1848) cannot access class sun.net.www.protocol.file.FileURLConnection (in module java.base) because module java.base does not export sun.net.www.protocol.file to unnamed module @0x67dd1848
    at play.utils.Resources$.isUrlConnectionADirectory(Resources.scala:32)
    at controllers.AssetsBuilder.$anonfun$assetAt$3(Assets.scala:817)
    at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:304)
    at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
    at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:70)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:68)
    at scala.concurrent.impl.Promise$DefaultPromise.dispatchOrAddCallback(Promise.scala:312)
    at scala.concurrent.impl.Promise$DefaultPromise.onComplete(Promise.scala:303)
    at scala.concurrent.impl.Promise.transformWith(Promise.scala:36)

I can access the application itself over http/https while Nginx acts as a proxy, but it seems the Play application itself cannot get the assets.

The route regarding assets is:

GET          /assets/*file             controllers.Assets.versioned(file)

and within the views I have:

<head>
    <link rel="shortcut icon" type="image/png" href="@assetsFinder.path("images/favicon.png")">
</head>

Any idea how I can debug this?

Upvotes: 2

Views: 856

Answers (2)

o-0
o-0

Reputation: 1799

Ok I found the answer: The reason I was getting the exception regarding java.base was because I was using java-9-openjdk which is not supported by Play for now it seems, and not java-8-openjdk.

You can read here or here how to setup and choose between different jdk versions in Ubuntu.

Upvotes: 2

rekiem87
rekiem87

Reputation: 1573

Mmm, to be honest it looks good, i have my assets defined as

# Map static resources from the /public folder to the /assets URL path
GET    /assets/*file    controllers.Assets.versioned(path="/public", file: Asset)

Then i can use it with

<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.ico")">

I did it based on the examples in https://www.playframework.com/documentation/2.6.x/AssetsOverview#reverse-routing-for-public-assets and worked with that with no problems.

Double check your permissions, but i do not think permissions have something to do with the error :(

Maybe you can also post the question in the gitter channel or in discuss

Upvotes: 0

Related Questions