Scala Play not found: value routes - scala

I have looked at other answers for this question but the answers are not related to my problem.
Firstly the following works in a html view:
<li>Tutorial</li>
but the same does not work in my tests and I get the error not found value: routes:
override val relativeUrl = Some(routes.CustomiseController.entry.url.tail)
I am testing the page has been loaded in my test by first getting the url to the controller, with reverse routing. I have already tried:
sbt clean
sbt clean compile
importing controllers.routes (which works in previous projects).
Double checking my routes file syntax.

Related

Splitting routes with prefix not working in Play 2.7 (worked in 2.6)

Our project uses multiple routes files.
The conf/routes file contains something like:
/some/stuff
...
-> /api/admin admin.Routes
-> /api/user user.Routes
We then have conf/admin.routes and conf/user.routes files, which contain the prefixed API routes.
I’m trying to upgrade from Play 2.6 (where this setup has worked fine, as well as on earlier versions), to Play 2.7. When compiling I get the error:
[error] /usr/src/backend/conf/admin.routes:401: value concatPrefix is not a member of object play.api.routing.Router
[error] GET /myAdminRoute #com.my.some.controllers.MyControl.list()
[error] /usr/src/backend/conf/user.routes:140: value concatPrefix is not a member of object play.api.routing.Router
[error] GET /myUserRoute #com.my.other.controllers.MyControl.list()
Looking at Play migration for 2.7:
I’m not using StaticRoutesGenerator https://www.playframework.com/documentation/2.7.x/Migration27#StaticRoutesGenerator-removed
Looks suspicious: https://www.playframework.com/documentation/2.7.x/Migration27#StaticRoutesGenerator-removed Router#withPrefix should always add a prefix`. But I’m just using Play conf/routes, so I’m not sure what I should be changing?
I assume the issue is because of that Router withPrefix change, but I’m not sure how to interpret it in terms of what I need to update. Has anyone else had this issue with Play 2.7?
I've just had another play with this, the first time was a few weeks ago - and I'm not getting the same error. I can repro if I start again and forget the SBT unlock; reload; lock cycle, which is probably the mistake I made before. This leaves me with Play 2.6 libraries installed with the Play 2.7 plugin.

Scala.js #JSGlobal - cannot perform run sbt

I'm struggling with an error and I cannot think of good solution.
I have class:
#JSGlobal("THREE.Scene")
class Scene extends js.Object {
def add(obj: js.Object): Unit = ???
}
and main:
[...]
val scene = new Scene()
[...]
scene.add(cube)
[...]
When I perform in sbt:
fastOptJS
and run my html page it all works great but problem comes when I want to run it with sbt:
run
Then I get error:
TypeError: Cannot read property 'Scene' of undefined
I've tried to replace:
#JSGlobal("THREE.Scene")
with
#JSExportTopLevel("THREE.Scene")
It run well when performed run in sbt but scene coudn't load on html page with error (in js console) saying that i do not have constructor (for Scene).
I do have in my build.sbt
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
My question is: How can I do it to have working html page and could run in with sbt without error?
Best regards.

Scala play - "not found: value routes" (Eclipse and IDEA)

Occasionally, and seemingly for no reason, I get "not found: value routes" compilation error in one of the view templates (after compilation).
This happens either in Eclipse or IDEA.
Googling finds this but it's not possible to add mainLang = SCALA in play 2.10 (I'm using version 2.1.2).
Cleaning the project / re-eclipsifying it / seems to work, sometimes, but is there any more permenant solution / work-around?
Thanks
Since there seems to be no answer, I'll at-least describe my workaround:
Instead of using
<link href=#routes.Assets.at("stylesheets/style.css") rel="stylesheet" type="text/css" />
in my template HTML, I'm using
<link href="assets/stylesheets/styles.css") rel="stylesheet" type="text/css" />
Since I'm not invoking routes.Assets.at, there is no issue with not finding the value routes.
(However, I'm guessing this workaround will easily crumble when I would have need of more complex templates)
This can happen if the routes file does not exist or contains no routes.
I have this working defining an Asset Controller
object Assets extends controllers.AssetsBuilder
and having the route for assets too in the routes conf:
\#Map static resources from the /public folder to the /assets URL path
GET /assets/*file premise.internet_org.controllers.Assets.at(path="/public", file)
sbt compile
Then IntelliJ loads the output of the compilation and everything just works for me.
This happens when there is no route configuration for your Assets in the routes file.
You must add this to your routes file:
GET /assets/*file controllers.Assets.at(path="/public", file)
I had such error when tried build Sihouette example project https://github.com/mohiva/play-silhouette-seed/tree/master. I commented or replaced code, that caused error. For example:
def view = silhouette.UnsecuredAction.async { implicit request: Request[AnyContent] =>
//Future.successful(Ok(views.html.signUp(SignUpForm.form)))
Future.successful(Ok)
}
After that build become successful - Twirl and Routes directories created in target/scala-2.X/. I run application and restore original code.
def view = silhouette.UnsecuredAction.async { implicit request: Request[AnyContent] =>
Future.successful(Ok(views.html.signUp(SignUpForm.form)))
}
I had added .disablePlugins(PlayLayoutPlugin) to my built.sbt "root" definition without changing the directory structure to match (see the link below explaining this). It switches from "Play application layout" to the "default sbt layout". The routes and application.conf are now expected in a different location on disk. I encountered both "not found: value routes" and "resource not found on classpath: application.conf" errors. I had copied this disablePlugins line from another project.
https://www.playframework.com/documentation/2.8.x/Anatomy#Default-sbt-layout
I had the same problem, its resolved when i drop the generated folders (target) and i restart my application
I had to go to the terminal and type "activator test" before Intellij would stop giving me these errors during IDE tests.

Play framework scala Intellij IDE action not found

I'm trying to setup basic play scala application with Intellij IDE (v 10.5.1).
I followed the instructions http://www.jamesward.com/2011/07/28/setup-play-framework-with-scala-in-intellij
When I start the application from the IDE everything is OK:
01:44:20,734 INFO ~ Application 'hello6' is now started !
But when I try to open a page in browser I'm getting the error in the output:
application.index action not found
Action not found
Action application.index could not be found. Error raised is Controller controllers.application not found
play.exceptions.ActionNotFoundException: Action application.index not found
at play.mvc.ActionInvoker.getActionMethod(ActionInvoker.java:585)
at play.mvc.ActionInvoker.resolve(ActionInvoker.java:84)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.Exception: Controller controllers.application not found
Looks like scala compilation just not happening for some reason. Everything works good if I'm running the application directly from play server.
Play v1.2.2, scala-module 0.9.1. Tried in Ubuntu 10.4 and Windows 7.
Updated adding routes file and Application.scala
# Home page
GET / Application.index
# Ignore favicon requests
GET /favicon.ico 404
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
# Catch all
* /{controller}/{action} {controller}.{action}
============================================================================
package controllers
import play._
import play.mvc._
object Application extends Controller {
import views.Application._
def index = {
html.index("Your Scala application is ready!")
}
}
This part:
application.index
Seems wrong, shouldn't it be Application.index? With capital A. Check you routes file, maybe it has that typo.
Found solution. In project structure
PlayFramework Dependecies and Project Libraries were not configured properly. After I fixed paths to ...play/framework/lib and ...play/modules/scala-0.9.1/lib scala compilation start working.
In the routes, put the action to be
controllers.Application.index
I was having the same problem. After going to SBT projects and refresh it went away.

Scala project won't compile in Eclipse; "Could not find the main class."

I have installed Eclipse 3.5.2 and today's Scala plugin from /update-current (that's Scala 2.8 final.) I can compile and run Scala projects consisting of a single singleton object that implements main().
But, if a project contains more classes, I receive the "Could not find the main class" error.
I have tried searching for the solution and I discovered:
Eclipse is correctly looking for the Main$ class, not the Main class
* under Debug Configurations, my main class is correctly identified as mypackage.Main
* my plugin is up to date and recommended for my version of Eclipse
* cleaning, restarting etc. doesn't help.
The same project will compile with scalac.
Thanks for any ideas on how to solve this.
EDIT: MatthieuF suggested I should post the code.
This snippet produces an error. It's not the most idiomatic code, but I wrote it that way to test my environment. I tried it as a single file and as separate files. It DOES work with scalac.
import swing._
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
object Hello {
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
BUT, if I nest the definition of HelloFrame within Hello, it works. This snippet runs perfectly:
import swing._
object Hello {
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
For me, the problem was that there was a build error (see Problems tab) which was preventing compilation; oops! The reason you see the error is that the run macro proceeds despite the failed compilation step, and attempts to run class files it expects to be there; they don't exist because there was a build error preventing compilation, so it says it can't find Main (not compiled).
Problem goes away when build can complete successfully, i.e. errors are fixed.
I guess, theoretically, there may be more complicated reasons your build is not completing successfully that are not listed in Problems.
One possibility is that you are trying to launch using ctrl-F11, but from a different class.
The Scala Eclipse plugin does not obey the defaults for Java launching. In Preferences->Run/Debug->Launching, there are some options Launch Operation->Always Launch the previously selected application, etc. This currently does not work in the Scala eclipse plugin. To launch a specified main, you need to launch it from the editor for the class.
There has been a bug raised for this. http://scala-ide.assembla.com/spaces/scala-ide/tickets/1000023-scala-launch--does-not-follow-jdt-behaviour
EDIT: This is now (mostly) fixed.
For me it was Eclipse specific problem. I noticed that .class file wasn't built at all. So bin directory doesn't have compiled classes.
When I manually compiled *.scala file using *.sbt and copied it to bin directory it was working as expected.
I tried different tips and tricks and it wasn't worked until I reinstalled Scala plugin in Eclipse .
I'd solve similar problem by executig "Project->Clean.." with next automatically building.
I had the same error message with a Java application made by myself.
The problem was that I deleted (though inside Eclipse) a jar that belonged to the Java build path, without deleting it from the Java build path (project's Properties window). When I did it the class could compile and run again.
Make sure that the .class files exist, usually below the bin directory.
In particular, if you have errors in unrelated files in the same project then the compilation may fail, and no .class files will be produced.
There can be the case of projects, containing errors, added to the build path of the application which prevents the completion of successful compilation. Make sure you remove any such project from the build path before running the application.
Removing these projects solved the problem for me.
Do you have a proper build tool setup? Like sbt have you installed it?
You can check its version by $sbt --version
If it is not setup you can download from here http://www.scala-sbt.org/download.html
You might have to restart your eclipse after installation.
Just copy your XXX.scala file code. Remove the package and create a new Scala Class. Paste your XXX.scala code. (If you are using maven, do a maven clean and build.) Run configuration again. This works for me.
I have faced this issue. I have just deleted the package name, created scala class, Written the same code, Set Build to "Build Automatically". Finally, It works perfectly fine.
Check scala-ide.log
For me the issue was that there were errors on:
AppData\Local\Temp\sbt_10d322fb\xsbt\ClassName.scala:16: error: not found: value enteringPhase
enteringPhase(currentRun.flattenPhase.next) { s fullName separator }
If you are using Intellij, mark directory as source root