How to build a play project in Intellij IDEA 2016.2.2? - scala

I have created a new play project in Intellij IDEA 2016.2.2 according to the tutorial: https://www.jetbrains.com/help/idea/2016.2/getting-started-with-play-2-x.html (the section "Creating a project"). As a result I have got a project with file Application.scala containing:
package controllers
import play.api._
import play.api.mvc._
class Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
}
Then I tried to build it using Build -> Rebuild project command. But I get build error:
Error:(9, 19) object index is not a member of package views.html
Ok(views.html.index("Your new application is ready."))
After starting the app using Run -> Run 'Play2Run' and including the target folder to the build process I managed to build the project via Build -> Rebuild project. But what should I do before building in the case I haven't launched the app via play?
Explanation why my question is not duplicate of another question:
I haven't found clean project opportunity in IntelliJ. Invalidating cache of IntelliJ doesn't help as well. Also the directories target/scala-2.11/src_managed/main and target/scala-2.11/twirl/main are absent in this new project. They emerge after Run 'Play2Run' and after that I can configure this Java Build Path, but I want to avoid using Run 'Play2Run'. How can I create these directories without the Run 'Play2Run'?

Related

New scala project in Intellij - Error: Could not find or load main class

I just created a simple helloworld scala project in Intellij. My main class is simply printing Hello World -
package xx.yy.zz
object HelloWorld{
def main(args: Array[String]): Unit = {
System.out.print("Hello World!")
}
}
My project structure
scala-test
|_src
|_main
|_scala
|_xx
|_yy
|_zz
|_HelloWorld
In the project structure settings, I have "scala" as my source folder. I am able to select my main class correctly in the application run configuration I created. So far so good. After this, when I try to run my run configuration, I get the dreaded error -
Error: Could not find or load main class xx.yy.zz.HelloWorld
At this point, I have tried all the things I could find on google like invalidating cache, reloading project, switching source folder to be "src" instead of "scala" and many others that I have lost track of by now. Please help!!
I didn't investigate the reasons for this issue but as a workaround, you can compile the project via sbt/shell sbt before running via Intellij.

Facing issue while trying to enable source code in IntelliJ for scala

I am new to Scala programming and I have just started with basic programs in scala in IntelliJ IDE.
When i use the below code
package com.allaboutscala.chapter.one.tutorial_04
object HelloWorld extends App{
println("hello from hello world")
}
I wanted to see the source code of App where it uses the main method, but when i tries to see the source code and when I try to download it, I am getting error like
Sources not found: Sources for 'scala-library.jar' not found. I have attached the screenshot also.It would be great if someone could guide me here.
Since you are using sbt, you need to enable downloading of sources for your project:
open IntelliJ Preferences
search "sbt" or navigate to Preferences | Build, Execution, Deployment | Build Tools | sbt
select "Download: library sources"
refresh the sbt project

IllegalArgumentException at createM3FromEclipseProject

With Rascal I am trying to create a M3 model of another eclipse project.
The java project I try to load is called eLib, it is opened in eclipse, I also can run the project. The project is located in my workspace.
However, if I use the following commands in my rascal console (in the eclipse plugin):
import lang::java::m3::Core;
import lang::java::jdt::m3::Core;
myModel = createM3FromEclipseProject(|project://eLib|);
I get the following error:
|rascal://lang::java::m3::AST|(6315,172,<156,0>,<158,87>): Java("IllegalArgumentException","Path must include project and resource name: /eLib")
at org.eclipse.core.runtime.Assert.isLegal(|file:///Assert.java|(0,0,<63,0>,<63,0>))
at org.eclipse.core.internal.resources.Workspace.newResource(|file:///Workspace.java|(0,0,<2164,0>,<2164,0>))
at org.eclipse.core.internal.resources.Container.getFolder(|file:///Container.java|(0,0,<215,0>,<215,0>))
at org.rascalmpl.eclipse.uri.ProjectURIResolver.resolve(|file:///ProjectURIResolver.java|(0,0,<107,0>,<107,0>))
at org.rascalmpl.eclipse.uri.ProjectURIResolver.getResourceURI(|file:///ProjectURIResolver.java|(0,0,<224,0>,<224,0>))
at org.rascalmpl.uri.URIResolverRegistry.getResourceURI(|file:///URIResolverRegistry.java|(0,0,<95,0>,<95,0>))
at org.rascalmpl.library.lang.java.m3.internal.EclipseJavaCompiler.setEnvironmentOptions(|file:///EclipseJavaCompiler.java|(0,0,<67,0>,<67,0>))
at sun.reflect.NativeMethodAccessorImpl.invoke0(|file:///NativeMethodAccessorImpl.java|(0,0,<0,0>,<0,0>))
at setEnvironmentOptions(|rascal://lang::java::jdt::m3::Core|(762,7,<28,76>,<28,83>))
at $shell$(|stdin:///|(10,45,<1,10>,<1,55>))
I hope one of you can help me.
Make sure the project you are trying to analyse is an actual Java project (not a generic eclipse project), and that it compiles (no red crosses in the project).

trouble with configuring scala project in intellij

I have been following the getting started with IntelliJ and Scala video from JetBrains and running into two problems.
I can't get it create or start a run configuration
I don't see the scala-test library as a selection under ProjectStructure-Modules-ChooseLibraries
What I've done so far is
Install Scala, add path and environment variables
Install Scala intellij plugin
Create new project set project sdk to java 1.7 and scala home to /usr/local/share/scala-2.10.3
Create an object that extends from App with a simple write line:
The one source file object
object HelloWorld{
def main(args: Array[String]) {
println("hello")
}
}
In the video they right click on the object file and can see a selection of run, but in my case I only see run as Scala Console. I can't seem to get the debugger to work and when I try to create a run configuration as an "Application" it says the src file is "not acceptable"
I'll recommend my simple project skeleton, to get you quickly up and running with Intellij, SBT and even Eclipse setup. Hope it helps!

Can I avoid compiling sources twice when running play2 and eclipse?

Currently I am running eclipse and play (with ~run) at the same time. When I change a file it will be compiled by play and by eclipse.
Is it possible to avoid one of those two compilation steps?
As far as I know, the eclipse plugin also uses sbt to build the project so maybe there is a way to execute the play "run" command inside eclipse?
(I am asking because my laptop is not very fast and compilation takes some time, and I would like to have the "Fast turnaround" as advertised on the play webpage ;)
You can turn off Build Automatically from the Project menu without losing any of the IDE functionality. Binaries will be built only by Sbt (on the command line).
A detailed guide for setting-up Play 2 with Scala IDE can be found on the Scala IDE website: http://scala-ide.org/docs/tutorials/play20scalaide20/index.html
I have not yet tried to run the play run sbt task in eclipse.
BUT you can run the server directly from eclipse.
Add "target/scala-2.9.1/classes" to your class path, use filters to include only your assets. (Project Properties, Java Build Path)
Choose "Run Configurations..." from the Run-Button-Menu.
Create a new "Java Application" configuration with your favourite name.
Main Tab: Use "DebugStart" as your main class
Arguments Tab: Configure any "-Dconfig.file=..." "-Dlogger.file" options you might need in VM arguments
Classpath Tab: Add the conf directory to the classpath (Advanced/Add Folders)
Create DebugStart.scala with:
import play.core.server.NettyServer
import java.io.File
import play.core.SBTLink
import play.core.TestApplication
import play.api.test.FakeApplication
import play.api.test.TestServer
object DebugStart {
def main(args: Array[String]) {
val app = FakeApplication()
val server = TestServer(9000, app)
server.start()
}
}
You can now start the app with run or debug. If you use debug, you can perform some code changes without any restart.
My version of DebugStart.scala actually contains some platform dependent hackish code to kill any running process, so that I can just hit F11 or CTRL+F11 to restart the application.
To ensure that your assets/sources are up to date run:
> sbt
...
[your project] $ ~ ;play-copy-assets;sources
IntelliJ Idea 12 (Leda) is coming soon. I'm using 11 for a while and there's no such problems but new version will offer much better Play 2.0 integration.