Play Framework 2.4 and IntelliJ Idea - intellij-idea

I am trying to open a play 2.4 project in IntelliJ but since things have changed I don't know how to do this.
In previous versions I could just run
activator idea
Or use the activator UI and click on generate intelliJ project, but in 2.4 the idea command doesn't seem to exist
[error] Not a valid command: idea (similar: eval, alias)
[error] Not a valid project ID: idea
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: idea (similar: clean)
[error] idea
[error] ^
And the UI seems broken, when I click on generate intelliJ project it tries to compile the app and gives this error:
play/Play$
java.lang.NoClassDefFoundError: play/Play$
Use 'last' for the full log.
Failed to load project.
I created the project from scratch using the play java template with:
activator new
I have also tried importing the folder as a project but intelliJ doesn't seem to identify it as a project

I run into the same problem, as I used IDEA to open a project folder, it had an play 2 app in a sub folder, then I import module (play 2 app) to the system.
And it works well.
After that I have changed the module folder name, then when I run the app, it displayed:
Not a valid project ID: "project team"
I re-checked the folder, and found that in the File -> Project Structure option, the name of module is "root", and the "team" is the module for whole project (not the module imported by SBT), so apparently, the module wasn't functional after I changed the module folder name.
So I found and removed all .idea folder, which is IDEA configureation, then re-open/re-import the module, still not work. I thought it's IDEA cache issue, it do have cache for the opened project, so I changed the project folder from team to something else, clean the .idea folders, and re-open/re-import it. It worked.
If the play app is in the project folder as a sub folder, to import the module at File -> Project Structure.
The project name should be "root" when running it in IDEA. So in this case, you should rename "project team" to "root" in the name field.

Solution 1
In my case (IDEA 2018.2), I changed the lazy val variable in build.sbt, it had the name "root" when my project name was "top", changed "root" to "top".
Before:
lazy val root = (project in file(".")).enablePlugins(PlayScala)
After:
lazy val top = (project in file(".")).enablePlugins(PlayScala)
Change project variable
Solution 2
The method proposed by Tom solved my problem partially, because after rebooting the IDEA I returned the project name back, it was necessary to change the variable from "top" to "root" in build.sbt.
Before:
name: = "top"
After:
name := "root"

Intellij IDEA lets you quickly create a Play application without using a command prompt. You don’t need to configure anything outside of the IDE, the SBT build tool takes care of downloading appropriate libraries, resolving dependencies and building the project.
Before you start creating a Play application in IntelliJ IDEA, make sure that the latest Scala Plugin is installed and enabled in IntelliJ IDEA. Even if you don’t develop in Scala, it will help with the template engine and also resolving dependencies.
Basically, install Play Framework, Scala plugins and import project into Intellij as SBT project. Don't use activator to create IDEA project files. More details here.

It seems I had not updated scala/sbt to the latest version in intelliJ
Once I had done this it noticed that it was a valid project, though the docs don't seem to mention you can import it as an SBT project, just how to create it as a new sbt project (which I did not want to do as I wanted to create it via activator)
I also had the project/play-fork-run.sbt file issue

I use Intellij Idea 16.3.3 and this problem appears sometimes. How I fixed it? You just need to open your SBT plugin and under your project get the context menu then you should choose "Ignore SBT project". After a current process is finished you should turn on this option again. This is work for me:)

Related

HelloWorld in Kotlin gives error "Could not find or load main class"

I spent the last 1,5 hour trying to make this simple tutorial work in IntelliJ IDEA, as you can see in this video.
When trying to run the code, I get the error:
/[...] -Dfile.encoding=UTF-8 src.HelloKt
Error: Could not find or load main class src.HelloKt
Caused by: java.lang.ClassNotFoundException: src.HelloKt
I have tried setting up SDK, invalidating cache, removing .idea and .gradle, rebuilding project, deleting the profile and adding it again. I tried those actions in different orders.
Here's a screenshot of the project:
It also complains Kotlin is not configured, but I have already configured it.
Here's the run configuration:
Here are the project settings:
Your Hello.kt file needs to be somewhere inside the src/main folder, probably in src/main/kotlin. This is different from the tutorial, because your project is using Gradle, and the one in the tutorial isn't. I think this is because newer versions of IntelliJ use Gradle by default for new projects, which wasn't the case when the tutorial was written.
The use of src/main/kotlin and src/test/kotlin as source code directories is a convention in Gradle (and Maven). When importing a Gradle project into IntelliJ, main becomes a module, and kotlin becomes a source folder within that module. The same goes for test. In your screenshots, the bold text and blue icons on main and test confirm that's how your project is set up. Files outside of those folders aren't treated as source files, which explains why your Hello.kt file isn't being compiled or recognised correctly.
It's likely that the default behaviour of IntelliJ when creating a new project has changed since this tutorial was written. In the tutorial, they select "Kotlin" as the project type and this creates a project that doesn't use Gradle. As a result, the project doesn't use the src/main/kotlin directory structure.
I can see from your video that you selected the same option, but on the next screen, IntelliJ still automatically selected Gradle as the build system for the new project. To match the project structure used in the tutorial, I think you would need to select "IntelliJ" as the build system.

How to open pom.xml project using IDEA

I am trying to learn about annotation processing by looking at this sample.
I've cloned it to my local machine and used IDEA to open it.
However IDEA tells me:
Project SDK not set up.
After setting up Java SDK, the project is not opening correctly. So how can I open this project?
The project structure :
annotationprocessing10
|
|------factory
|-----annotation
|------pom.xml
|-----processor
|------pom.xml
|-----pom.xml
|-------factory-sample
I tried opening annotationprocessing10 (root) directly and also tried factory directly but neither worked. Here is a screenshot of the directory structure:
The given repo is not a maven module (no POM.xml in the base directory), the maven modules are the projects inside.
Make sure you import the modules inside the root directory in IDEA to identify it as a maven project.

SBT compilation for play framework 2.x disabled by default

I created a new Play Framework project using the activator, activator new my-project-name and then I selected the play-java template and the project is created with no errors.
Then I import the project into my IDE, IntelliJ, as a SBT project. When the project is imported a popup is shown saying: SBT compilation for play framework 2.x disabled by default.
On IntelliJ project's panel it doesn't show all (mostly the files with the code) files. Just a handful of them.
The build.sbt file looks like full of compilation error (pretty much all the lines are red underlined).
Here's the build.sbt file
name := """my-project-name"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
fork in run := true
I can compile and run the code with activator ui with no errors. So, why isn't IntelliJ fully importing the project and it shows me SBT compilation for play framework 2.x disabled by default message?
I googled around and couldn't find any hint related to this so I'm kinda lost here.
EDIT: -------------------------------------
I closed the project on IntelliJ and deleted the project folder. Closed IntelliJ and using activator I created again the same project. Using activator ui I compiled the project. Then I fired up IntelliJ and was prompted to either open a project, create a new one or import a project.
Selected import a project and did the normal "import a project steps" and IntelliJ imported the project with no hassle. But if I try to import the project while with an open project on IntelliJ I get the same problem that lead me to make this question. Maybe this is a bug on IntelliJ?
EDIT 2 ------------------------------------------
The solution to these two problems (the "SBT compilation for play framework 2.x disabled by default" and the files not showing on IntelliJ) can be fixed with user3384225 and DarkShadow answers.
Preferences > Languages & Frameworks > Play2
Under 'Compiler' enable 'Use Play 2 compiler for this project'
I Stumbled upon this problem myself when configuring play framework for IntelliJ IDEA IDE (version: 2017.3). I overcame this problem by following the steps below.
Navigate to:
File --> Settings --> Languages and Frameworks --> Play2 --> Compiler tab
and inside the compiler tab:
put a tick to the Use Play2 compiler for this project
Hope this helped.
Similar answer to user3384225's answer was posted here:
https://devnet.jetbrains.com/message/5560914
They say:
Settings -> Langauges & Frameworks -> Play2 -> Compiler -> User Play 2 compiler for this project
I am also a newbie and was facing the same problem till yesterday. Probably you are trying to open the project through File->open.
Try the steps below:-
File->New->Project from existing source->select the build.sbt from the project you created using the activator->Import project from external model and select SBT from the options->OK.
It will take some time to import files and to create the settings required for intellij idea project.
I am using intellij idea 14.1.5. It worked for me hope it will for you also.
For current projects, you can fix this by using File->Invalidate Caches/Restart..
Most probably you have solved you problem, but just to help others
What you just have to do is -> check the option "Use Play 2 compiler for this project" given under Preferences -> Languages & Frameworks -> Play2 -> Compiler
Close the project and then import the project as sbt project.
Intellij will automatically dump and index the project dependancies.
Stumbled upon the same problem today. Solved by wiping the ~/.IntelliJIdea14 directory. Unfortunately any other things I've tried didn't help.
Just use: File->New->Project from existing source->select the build.sbt from the project you created using the activator->ok.
and it's done.

Intellij IDEA - JavaFX packager : access denied

I'm trying to generate an artifact of my JavaFX application using Intellij but for some reason I always end up having JavaFX packager throwing an access denied error on my output directory.
Generating a simple jar works fine though.
I'm using it on Windows 8.1 with Java 8.
I had the same problem. I kind of solved it:
by ticking the "Build on make" box in the Project Structur Dialog
starting a Run of my Java App in Intellij Idea
Now the executable jar magically appeared in my build folder. God knows why.
I had this problem and solved it by deleting the Artifact from IntellIJ, then deleting the "out/artifact" previously created folder where it tried to build my jar and finally re created an artifact from scratch. For no specific reason it now worked.
I have encountered the same problem recently. I checked the permissions of the directory and can read and write. Later I deleted the artifact and re-created a new one to solve the problem. I hope to help people who have encountered this problem.
I had this problem. I ran into it because When I added artifact with + button in Project Settings->Artifacts, I selected JAR artifact , and change JAR to JavaFx Application from type drop down box on right side pane. Later, I removed this artifact and pressed + button, then selected JavaFx Application from drop down list, then it was builded successfully. My JDK version is 8.
When I call JavaVXPacker from the command line I get the following:
C:\Users\Ingo>javafxpackager -help
javafxpackager.exe has been renamed javapackager.exe.
The original file may be removed in a future release in lieu of javapackager.
Please update your scripts.
...
...
So I guess IntelliJ has to update it's script to re-enable the feature???
(using Windows 10 and JDK Liberica 15+36)
Go to File > Project Structure
Click on Artifacts on the left panel.
Thereafter click on the plus icon to add a Jar From modules with dependencies…
A pop-up will be shown and there you would have to select for the startup class of your project.
Click on OK twice to save the changes.
Lastly go to Build > Build Artifacts... And select build action.
Now your jar will be generated in the out folder of your project.
For a more details guide, please refer to this post

IntelliJ IDEA and PlayFramework modules

After a lot of good comment about IDEA, I decided to give it a try. I downloaded the Community Edition and would like to use it for PlayFramework development.
I have followed official documentation and some other information gathered around, but I have not succeeded completely. When using a project with differents (play) modules, the different classes are not found.
For example when using Secure module, IDEA keeps complaining about not finding Secure.class. It has to be a classpath issue. I tried to attach Java source & classes ($PLAY/modules/secure/) in module settings (F4), class is still not found. Did I miss something?
BTW, I have done a play dependencies and play idealize, which seems to add another module Secure into project in IDEA.
Thanks,
The answer is to run the following:
play deps
play idealize
This forces the IDEA .iml project file to be refreshed with the updated class path entries for the new module (in this case Secure).
A issue I came across using IntelliJ and Playframework.
The log4j.properties file or log4j.xml file are not in classpath by default. You have to add the conf as a source folder in module settings.
You need to add the Secure module you have created in IDEA as a dependency to the main application module:
Go to File -> Project Structure
Choose the main module
Choose the Dependencies tab
Click Add -> Module Dependency
Choose the IDEA Module you created for the Play Secure module
Also make sure you have the correct source path selected for the Secure module in IDEA.