Using Play 2.4 with a renamed `conf/routes` file - playframework-2.4

My simple Play 2.4 project does not compile when I rename the conf/routes file to something else, e.g. conf/hello.routes. The reason I'm doing this is to enable composition of APIs while allowing them to be developed in separate git repositories and sbt projects.
The idea of multiproject support is based on this project and blog post - but that's using Play 2.3.
The error I get is:
$ sbt test
...
[info] Hello should
[error] ! give {hello: true}
[error] Unable to provision, see the following errors:
[error]
[error] 1) Error in custom provider, java.lang.ClassCastException: interface play.api.routing.Router is not assignable from class hello.routes
[error] while locating play.api.test.FakeRouterProvider
[error] while locating play.api.routing.Router
[error]
[error] 1 error (InjectorImpl.java:1025)
[error] com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)
[error] com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
[error] play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321)
[error] play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:316)
...

Got this resolved (code in the git repo now works).
The problems were likely connected to both of these:
the Controller implementation wants to be within a package controllers.hello instead of just hello
in the application.conf file one should omit the controllers namespace, i.e.
play.http.router = app.Routes
I learned this simply by comparing this code with samples that work.

Related

sbt / native-packager, new jdeps error: java.lang.module.FindException: Module java.activation not found, required by java.xml.bind

I have not changed my setup as far as I can see. As of today, trying to run sbt native packager with jlink gives this error:
[info] Running: jdeps --multi-release 11 -R ...
[error] Exception in thread "main" java.lang.module.FindException: Module java.activation not found, required by java.xml.bind
[error] at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
[error] at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
[error] at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
[error] at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
[error] at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
[error] at jdk.jdeps/com.sun.tools.jdeps.Main.run(Main.java:64)
[error] at jdk.jdeps/com.sun.tools.jdeps.Main$JDepsToolProvider.run(Main.java:73)
[error] at java.base/java.util.spi.ToolProvider.run(ToolProvider.java:137)
[error] at ru.eldis.toollauncher.ToolLauncher.runTool(ToolLauncher.java:68)
[error] at ru.eldis.toollauncher.ToolLauncher.lambda$main$1(ToolLauncher.java:33)
[error] at ru.eldis.toollauncher.ToolLauncher.main(ToolLauncher.java:48)
How do I fix this? I tried adding javax.activation to libraryDependencies, that doesn't seem to have any effect or anything to do with this problem.
Edit: The root problem of seems to be my dependency on Pi4j 1.4, which depends on javax.xml.bind:jaxb-api which in turn depends on javax.activation:javax.activation-api. Now I don't understand much of this Java module stuff, but javax.activation-api does exist on Maven, so why does jdeps complain? If I exclude javax.xml.bind, it works, but now I'm worried I'm actually missing stuff on the class path.
javax.activation has been removed since java 11.
To fix it you can:
Download the javax.activation jar and run the command by adding this jar on module path:
jdeps --multi-release 11 -R --module-path path\to\javax.activation.jar ...
Running this command with java 8 jdeps

Compiling kafka schema-registry fails for building kafka-connect-hdfs

I'm trying to build kafka-connect-hdfs by following this FAQ.
While trying to compile schema-registry, I get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-
compiler-plugin:3.6.1:compile (default-compile) on project kafka-
schema-registry-client: Compilation failure
[ERROR] /Users/workspace-name/kafka-connect/schema- registry/client/src/main/java/io/confluent/kafka/schemaregistry/client/s ecurity/basicauth/SaslBasicAuthCredentialProvider.java:[40,42] cannot find symbol
[ERROR] symbol: method
loadClientContext(java.util.Map<java.lang.String,java.lang.Object>)
[ERROR] location: class org.apache.kafka.common.security.JaasContext
Are any modifications required? Appreciate any suggestions. Thanks

org.mockito.internal.matchers.LocalizedMatcher cannot be cast to org.mockito.ArgumentMatcher with "any" matcher when running "activator test"

I'm having an error in one of my specs2 tests. The project is implemented with Play!Framework (Scala).
This is my test:
class AmazonEmailSenderSpec extends Specification with Mockito {
"AmazonEmailSenderSpec#sendEmail" should {
"Send Email with correct data" in {
val client = mock[AmazonSimpleEmailServiceAsyncClient]
val emailSender = new AmazonEmailSender(client)
emailSender.sendEmail(Email(subject, content, from, to, cc))
val captor = ArgumentCaptor.forClass(classOf[SendEmailRequest])
there was one(client).sendEmail(captor.capture)
val sendEmailRequest: SendEmailRequest = captor.getValue
}
}
}
This test works fine if I run it on intellij, but somehow, it fails when I run it on the console using the play activator:
activator test
I get:
[info] AmazonEmailSenderSpec#sendEmail should
[error] ! Send Email with correct data
[error] org.mockito.internal.matchers.LocalizedMatcher cannot be cast to org.mockito.ArgumentMatcher (ArgumentsComparator.java:25)
[error] org.mockito.internal.invocation.ArgumentsComparator.argumentsMatch(ArgumentsComparator.java:25)
[error] org.mockito.internal.invocation.ArgumentsComparator.argumentsMatch(ArgumentsComparator.java:17)
[error] org.mockito.internal.invocation.InvocationMatcher.matches(InvocationMatcher.java:56)
[error] org.mockito.internal.invocation.InvocationsFinder$RemoveNotMatching.isOut(InvocationsFinder.java:145)
[error] org.mockito.internal.invocation.InvocationsFinder$RemoveNotMatching.isOut(InvocationsFinder.java:137)
[error] org.mockito.internal.util.collections.ListUtil.filter(ListUtil.java:16)
[error] org.mockito.internal.invocation.InvocationsFinder.findInvocations(InvocationsFinder.java:20)
[error] org.mockito.internal.verification.checkers.MissingInvocationChecker.check(MissingInvocationChecker.java:32)
[error] org.mockito.internal.verification.Times.verify(Times.java:36)
[error] org.mockito.internal.verification.MockAwareVerificationMode.verify(MockAwareVerificationMode.java:21)
[error] org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:76)
[error] org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
[error] org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:37)
[error] org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:36)
[error] org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.access$000(MockMethodInterceptor.java:17)
[error] org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$DispatcherDefaultingToRealMethod.interceptSuperCallable(MockMethodInterceptor.java:96)
[error] com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceAsyncClient$MockitoMock$1778874818.sendEmail(Unknown Source)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11$$anonfun$apply$12.apply(AmazonEmailSenderSpec.scala:27)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11$$anonfun$apply$12.apply(AmazonEmailSenderSpec.scala:27)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11.apply(AmazonEmailSenderSpec.scala:27)
[error] integration.email.AmazonEmailSenderSpec$$anonfun$1$$anonfun$apply$11.apply(AmazonEmailSenderSpec.scala:19)
I can't understand why a LocalizedMatcher is being used by activator when an ArgumentMatcher should be used instead.
The signature to the method I'm trying to match is:
public SendEmailResult sendEmail(SendEmailRequest sendEmailRequest)
Couldn't really find any hints on google. Any ideas? Am I missing something really silly?
This is an old question, but I just happened to run into the same issue in 2017:
A solution that worked for me (JUnit/Specs2, in a mixed Java/Scala) project:
I forced mockito to use the latest version 2.7.11. But I also had a dependency on org.specs2:specs2-mock_2.12:3.8.6 which is still based on mockito 1.9.5. See maven central.
Somewhere here lies the problem. I removed the dependency on specs2-mock and Specs2's mockito syntax sugar and replaced it with plain mockito code. Voila! The error mentioned above was gone.

Can't get path to resource

I am trying to use Scala macro annotations with this library.
I have a schema file at src/main/resources/avsc/FriendRequestAcceptedGson.avsc
I am trying to refer to it in my code as follows:
#AvroTypeProvider("/avsc/FriendRequestAcceptedGson.avsc")
#AvroRecord
case class FriendRequestAcceptedGson()
This is the error I get:
[error] /home/lee/Code/bigdata-friends/java/etl/src/main/scala/com/mxit/bd/friends/etl/Runner.scala:64: exception during macro expansion:
[error] java.io.FileNotFoundException: /avsc/FriendRequestAcceptedGson.avsc (No such file or directory)
[error] at java.io.FileInputStream.open(Native Method)
[error] at java.io.FileInputStream.<init>(FileInputStream.java:146)
[error] at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:504)
[error] at org.apache.avro.Schema$Parser.parse(Schema.java:922)
[error] at com.julianpeeters.avro.annotations.util.SchemaParser$.getSchema(SchemaParser.scala:20)
[error] at com.julianpeeters.avro.annotations.AvroTypeProviderMacro$.impl(TypeProviderMacro.scala:23)
[error] #AvroTypeProvider("/avsc/FriendRequestAcceptedGson.avsc")
Resources are compiled into your JAR file. You must find them with a ClassLoader, not in the file system. The java.io.FIle class only knows how to look in the file system. Now, if you're trying to open the source file (which may not be present when the JAR is deployed), it will depend on where your current working directory is relative to the file. Probably it is at the root so the path you need to use is the full relative one: src/main/resources/avsc/FriendRequestAcceptedGson.avsc

sbt stage : not a valid command

I am trying to follow the tutorial for scala and spray with this great template : http://typesafe.com/activator/template/activator-akka-spray
Then I follow instruction for Heroku deployment : https://devcenter.heroku.com/articles/getting-started-with-scala
I encounter a problem when running the command "sbt clean compile stage" in order to prepare a deployment on Heroku. Here is the error message :
[info] Loading project definition from /.../activator-akka-spray/project
[info] Set current project to activator-akka-spray (in build file:/.../activator-akka-spray/)
[error] Not a valid command: stage (similar: last-grep, set, last)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: stage (similar: state, target, tags)
[error] stage
[error] ^
Has anyone encountered a similar error ?
Thanks in advance for any help.
Add the StartScriptPlugin from Typesafe in the build.sbt, as mentioned in the documentation.