Generating Scala Play project for IntelliJ - scala

I am new to Play Framework. I wished to make a simple hello world project using SBT (without activator), but unless I did something wrong it seems to me that not all of the files and folders are generated.
Followed the instructions here: http://www.playframework.com/documentation/2.3.x/IDE
Can anyone direct me to some resource that could help me?
Thank you!

First, follow "Create a new application without Activator" section here:
http://www.playframework.com/documentation/2.3.1/NewApplication
Then run "idea" in SBT console to generate .idea and .idea_modules directories with IntelliJ IDEA configuration. Afterwards, use File - Open dialog in the IDE.
The steps above will create an empty application. You will have to create a controller, a view and routes file yourself if you don't want to install activator. Still I advise you to install activator where you'll find plenty of templates including "hello playframework" that would fit your needs.

Related

Could not find or load main class in scala in intellij IDE

I have searched for this error, but the answers were for Java,
but my case is Scala. I am trying to run this project in IntelliJ IDE
sentimenAnalysis, but it throws an error. This is also the structure of the project. Class Not found
Update 1 According to answers, Adding $ at the end of the name of search class
Update 2 after adding sbt task:
Update 3
My problem was resolved by importing the project, instead of getting it directly from GitHub, probably the manual configuration that Mike Allen said could resolve the problem, but I couldn't successfully apply that.
My problem was resolved when I marked "src" folder as sources root.
Right-click on (folder) src -> Mark Directory as -> Sources Root
Probably you imported project somehow wrong. I see scala folder is not highlighted as sources.
Usually, you don't even need to setup Run configuration manually for Scala SBT project. Do you have Scala and SBT Plugins in your IDE?
You should open SBT projects through "Import project" and choose "build.sbt" file. I would also recommend enabling auto-import to install all of the dependicies.
That's how it look for me:
If you still wanna make it manually your configuration should work. That's my Run configuration that works:
You will get this error if you tried to open the project and imported it incorrectly. I would open the project like this in Intellij:
File>New> Project from Existing Source>(select) Import project from external model>
(select)sbt
click Next>Finish
To fix this issue in my project I invalidated caches and restarted:
In my case the object in the object MyObject extends App was nested, if you have it unested meaning in your scala file it's not under any other object it made it work.
Netsted caused this error in intellij:
object External {
object MyMain extends App // Could not find or load main class in scala in intellij IDE
}
While the below unested worked:
object External { }
object MyMain extends App // Worked!
Hi I solved this problem by defining the class in src package under main and by setting up the configuration as default.
Create a new project and make sure SBT is proper loaded along with Scala Library. This happens with many times, bad internet connection or failure of Scala library/SBT loading might be some of the reasons.
Best of Luck for Next Project, Happy Developers & Coders.
Had a similar problem with latest Intellij IDEA build (2022.1.1) and scala 3.1.2 - both sbt and Intellij scala projects. For me the solution was to use non-ascii path.
#SeriousDron answer helped me with my problem. You need to make sure you have Scala language installed in IntelliJ. You can do this by going to Settings > Plugins > search for "Scala". Now, it will automatically pick up your .sbt file and project.
I met the same issue, please check the whole execute command and check the configuration, make sure the compiled files path is correctly configured.
refer to my screenshot:

How to use SBT to create an IDEA plugin project?

We can use IntelliJ-IDEA to import an normal SBT project easily, but I'm trying to write an IDEA plugin project with Scala, and I want to use SBT to manage it(the dependencies).
But now I don't know how to do it, and not sure if it's possible, so I have to use IDEA to create an IDEA plugin project manually, and commit the .idea/* files to git, which is not good.
Is it possible to use SBT to create an IDEA plugin project?
I am not sure how the exact code would look. But the play framework does something like what you want. They let you create an IDEA project with
[My first application] $ idea
So you can .gitignore the .idea/* folder and every developer can easily create their own IDEA project if they want to use an IDE.
Their documentation describes how you use it, so it should be easy enough to find the code that actually generates the project: https://www.playframework.com/documentation/2.0/IDE

ScalaTest Run Configuration in Eclipse: cannot find Suite Class

Problem: I cannot setup Run Configurations to run scalatest for the Scalatests in my project.
Steps to reproduce:
Right click on Scala Suite and click on Run as -> Run configurations..
On the left, I see a configuration template for ScalaTest. I click on New and fill the Name but it cannot find the suite-class.
Note: It is mentioned here that I should see Run as -> ScalaTest - Suite but I do not see that option. I tried using context menu in the editor, and in the package explorer
Steps taken:
Using: Scala IDE for Eclipse version: 2.1.0.m3-2_09
Using SBT, assemble project, run eclipse command and then import project and dependencies into Eclipse
Project compiles. ScalaTest code compiles(scalatest_2.9.2-1.8.jar is in the 'Referenced Libraries' configuration)
I've been fighting a similar problem for the past few days; Lily / Jimbo's answer didn't quite match my situation, but helped me find the right direction.
In my case, I was using a third-party library that I'd copied in. The package names of the classes and tests matched, but the folder structure did not -- all of my tests were directly in Play's "/test" folder, rather than in folders that matched the package names. This didn't show any errors, but was broken: packages ought to match folders. When I built the right folder structure underneath test, and recompiled, the expected "Run As -> ScalaTest - Suite" options showed up.
Don't know if your problem is the same, but you might check this if you haven't already found the issue...
This could be caused by a misalignment between the scalatest and the scala eclipse IDE version. Try scalatest_2.9.0-2.0.M5b.jar or scalatest_2.10-2.0.M5b.jar. The former jar definitely works with ide 2.0.9.x so maybe the new version needs the 2.10 jar. Pick your version carefully from here
Willem's answer is what worked for me. Getting both plugins from the same update site (from the list on Scalatest's github site), seemed to work for me using Kepler.
for my case, one click on 'Reimport All Maven Projects' icon, like 'Refresh' icon, solved the problem.
Not sure if you fixed the error, but I had similar a error yesterday and was pulling my hair trying to fix it (none of the suggestions I found by googling seemed to help me). So for me, it turns out that it's as easy as package hierarchy in my test suite.
I am using the play framework, so naturally my folders look like this controllers.package1.package2.... and this applies to my test folders also.
Now my test classes however, have the package definition package1.package2..... (no "controllers" as prefix).
If I run the tests on sbt/play command prompt, it's not a problem. But running them through Eclipse would give me the problem you described.
So anyways... thought I'd share this, in case this could help.
it's a bit annoying combined with the view template compile issue in play framework. but my approach is to regenerate the eclipse project file and add view template path into the class path

Intellij Idea setup for Scala, clarification needed

Using IntelliJIdea 12, i downloaded the Scala plugin and created a HelloWorld application.
The following import seems odd. Why does IDEA not recognize this to be a Scala Application? Is my setup incomplete?
I checked to see where does my compiler points to and got this. Don't really see a way to navigate IDEA to my scala installation.
Please advise.
When creating a new Scala project from the wizard IDEA can download and configure everything for you:
Settings can be changed later in the Scala Facet:
and in Compiler:
Libraries configuration:
Code and imports completion is available from the Scala library:
You need to add Scala as a framework for your project.
To do this, right click on the top level directory in your project, choose "Add Framework Support..." and select Scala. Then Scala will be added as a "Facet" of your project.
Here is a good page with more info:
IDEA Scala Project Configuration Explained
I got around this by downloading the Scala library from scala-lang.org, unzipping it and then pointing the project to it. It worked fine after that. But of course, I'm an eclipse guy so perhaps someone else might be able to give you a better automated (?) solution. Here's what my project looks like in Module Settings -> Libraries:

Starting a new project with sbt-idea plugin

I am new to sbt and the sbt-idea plugin. I created a new project with the plugin and when opening the generated .idea file inside IntelliJ and compiling I am getting that "please specify compiler in Scala facet". When looking on the scala compiler facet all I see is "buildScala" in red.
Since I saw many here are using the plugin, can you explain the steps you took to correct this?
I have this problem when I use the sbt-idea processor, and then import the module into an existing IDEA project. However, when I open the project created by sbt-idea I do not have the problem.
I have not been able to fix the red buildScala problem with imported modules. I suspect it would require tomfoolery in the project files, as I can't find config options to correct it via the GUI.
Personally, I always install sbt-idea as a processor in every new SBT install I make. (See "Usage as processor" in the previous link). Then the correct way to generate project files is simply sbt idea.
Can you clarify exactly the steps you followed that led to the error?