I just start using IntelliJ-14 and I want to know about a scratch file. If I create a java scratch can I compile this as a normal Java class.
What I Have Already Tried
Create a Java class in a scratch file but unable to find any way to compile this.
What I am looking for rather than creating a new Java file in an existing project for running some test code I just want to use scratch file and write some test class with the main method and after complete running close the scratch file. Is that possible?
Executability for Java scratch files was added in IntelliJ 15, so you must upgrade for that feature.
You have several option how to run/debug the scratch file:
Click the icon next to the main method/class
Hit Control+Shift+R (Control+Shift+F10 on Linux/Windows) somewhere within the scratch file
Right click inside the method/class and select appropriate run/debug option
Related
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.
Every time I create a new JavaFX project in IntelliJ it loads a simple HelloWorld project in it. How can I make it empty instead (without the need to delete those .java files every time)? Also how can I choose to create the project without a building system (as you can see in the picture, I'm always forced to create the project with Maven or Gradle)
When creating the new project, choose "Java" instead of "JavaFX".
A JavaFX application is just a Java application, so if you don't want the additional things which IntelliJ is doing when you choose to create a JavaFX project (e.g. supplying example code and associating with a build system like Maven or Gradle), you can just choose a basic Java application project from the wizard and it won't do those other things.
See the section in openjfx.io documentation titled "JavaFX and IntelliJ IDEA" for other steps you need to take:
Set the project JDK
File -> Project Structure -> Project
Create a JavaFX library in Idea
File -> Project Structure -> Libraries
Point to the lib folder of the JavaFX SDK.
Add VM options for the module path
Run -> Edit Configurations...
--module-path /path/to/javafx-sdk-15.0.1/lib --add-modules javafx.controls,javafx.fxml
For windows use quotes around the path and \ rather than /.
Run the project
Run -> Run...
You might also need to take the actions identified in the accepted answer to:
How to convert a normal java project in intellij into a JavaFx project
But that answer was written a while back and setting the resource copy configuration to include JavaFX fxml and css files might not be needed anymore.
Now, you might think that is annoying amount of things to do, and I might agree with you.
Sometimes IntelliJ IDEA has problems running, debugging, or showing code-coverage for PHPUnit tests. This can occur when the classes it generates are not compatible with the version of PHPUnit you have.
In my case, it's IntelliJ IDEA 12.1.6 versus PHPUnit 4.0.14, which always fails with this message:
/usr/bin/php /tmp/ide-phpunit.php --configuration /home/username/Documents/stuff/phpunit.xml.dist
Testing started at 5:32 PM ...
PHP Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest) in /tmp/ide-phpunit.php on line 496
PHP Stack trace:
PHP 1. {main}() /tmp/ide-phpunit.php:0
Process finished with exit code 255
The code it is generating in /tmp/ide-phpunit.php does not contain a new method required by PHPUnit 4.x.
Things which I've tried that don't work:
Fixing the file manually and marking it read-only causes IntelliJ to stop and complain that it cannot replace the file.
Setting up a "run-before" command to automatically patch the file is insufficient, because it doesn't seem to work for debugging nor code-coverage, only regular runs.
The best solution I've found is to patch your IntelliJ installation with a manual fix. These instructions assume Linux paths, but the same basic process should be possible on Windows.
Find the JAR
First, find the php.jar file in your IntelliJ installation. JAR files are a kind of ZIP file, you can open (and modify) both of them with the same tools. On my system, it was present at:
/home/username/.IntelliJIdea12/config/plugins/php/lib/php.jar
Make a backup of php.jar, since we're going to edit it.
Extract the template
Using a popular ZIP-file tool (like 7-Zip) open php.jar, and find the compresesd file inside called:
scripts/phpunit.php
Extract this file to a temporary location where you can edit it.
Add the method to the template
Inside the file, we need to find the class IDE_PHPUnit_Framework_TestListener, which in my case is around line 303. On that class, we need to add a new method:
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time){}
Save the file when you are done.
Update the JAR with the new template
Now overwrite scripts/phpunit.php inside the JAR with your new version. Depending on your ZIP tool, this might have been as easy as double-clicking the file to open it, saving your changes, and clicking a confirmation prompt, but it depends on what you're using.
Restart IntelliJ
Now you should be done! Running, debugging, or generating code-coverage data with PHPUnit should be just a convenient click of a button.
Note that if you update your PHP plugin, it will probably overwrite the fix and you'll need to re-apply it again.
Ok, so I'm working on a project using IntelliJ and trying to take advantage of its cucumber functionality. I've not worked with the java flavour of cucumber, but IntelliJ seems to want the step definition files in a specific location, relative to the feature files.
I found this: how to define step definitions location for cucumber in intelliJ 12 and other sources that pointed me to been able to add the "glue" property of my run configurations which tells cuke which package to find the step file. So I am at a point where I can run my tests via IDEA. BUT I need to set this every time I run a new test, as Ctrl+Alt+F10 or right click+run test will not start the test with this flag. Also, the ide support is screwed as IDEA doesn't know where the steps are, it doesn't auto complte or Ctrl+Click navigate to steps.
Is there a way to the the IDEA project to always look for steps in a given package both when running the tests and for its auto complete?
Creating self answer for others who might have this problem. My project did not have the steps marked as test source root, and although I DID do this, it was not until I closed and reopened my project that they were picked up. So a simple restart was my answer.
You can set the glue location globally by opening "Edit Configurations -> Defaults -> Cucumber Java -> Glue" and add the package names.
(IntelliJ 12.1.4)
Go File->Settings--> plugins
Install Cucumber for Java plugin
Then you can manage cucumber plugin as shown below
This should redirect you to step definition when you click your test.
Hope this helps
IntelliJ supports a plugin for Cucumber-Java/Groovy. Installing this plugin will enable the navigation from Steps mentioned in the feature file to the Step Definitions.
And after creating the Step Definition, navigation is easily possible
I go in EditConfiguration, Glue section and i put the path from the package above and the package where is your class for steps, ex:
CucumberFramework.stepsDefinitions
It is really nonsense :) but in in my case when IDEA refused to add steps definition automatically due to some plugins installed, e.g. Cucumber for Scala and suggested deleting them that i cant since i need them in other project. So, long story short, to add (Create step definition) you need to create Class in 'glue' dir and some fake Cucumber implementation, build one more time and it resolved my issue.
Background:
When I use IDEA 2018.2
And Java 8
And Cucumber info.cukes:cucumber-java:1.2.4
#When("^I created a Class and put there fake step implementation$")
#And("^I run gradle build one more time :)$")
#Then("^This Class will be able for me from the feature file by ALT+ENTER as usual$")
#And("^It resolved my issue when I was not able to automatically generate step definition$")
I have created a test suite (making a main file and calling other test cases that I like to run) .Now is it possible to make a jar file of test suite that i have made so that just by clicking on the jar i can forcefully start the test .Also is it possible to create c config value outside jar.I am using java programming language.
Help plz.
If you are using eclipse as an ide you can create a jar file very easily.
Right click on project.
Go To Export.
Select Jar or Runnable Jar as per your use click on next.
Specify the main file name.
Click on Finish.
Before doing above steps. i mean
Right click on project.
Go To Export.
.
.
.
.....on Finish
Clean the project to avoid “duplicate entry” error when exporting Java project to JAR with Eclipse.
Enable Auto Refresh in Preferences - General - Workspace - Refresh Automatically (called Refresh using native hooks or polling in newer builds)
Or Just right click on the project and click Refresh.
to avoid “resource is out of sync with the filesystem” error.
Right click on project.
Go To Export.
Select Jar or Runnable Jar as per your use click on next.
Specify the main file name.
Click on Finish.