What is required to run a hello world in kotlin with IntellJ - kotlin

I have a Mac (Catalina OS) with Java 15 and IntelliJ 2020.2 (community edition) installed. The kotlin plugin is also installed. When I create a new Kotlin Project, add a main function, then there is way to run it, there is no 'Start' Button next to the main function. The problem is obviously that it doesn't find the runtime. The iml file looks as follows
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
When I click on 'add framework support', I can add a new KotlinJavaRuntime which then just appends an <orderEntry> to the iml file with the name KotlinJavaRuntime (2).
I don't want to use maven or gradle here. I know that gradle can resolve the dependencies for me. I just want a plain vanilla Kotlin hello world project. The documentation has a 'Getting Started with IntelliJ IDEA' section which just mentions the Kotlin plugin for IntelliJ. There seems to be no requirement to have gradle or maven installed, the plugin should do it.
I know that you can use brew install kotlin to install the SDK manually, but then the documentation is wrong and the plugin alone cannot run Kotlin with a prior manual installation of the SDK or the usage of maven/gradle.

I think I know what happened in this case.
The Kotlin Code was loaded as an 'IntelliJ' Module inside a Java project that was using maven. In IntelliJ there's a hidden folder .idea/libraries/ which was missing the description of the Kotlin Runtime (this makes sense, since the dependencies were managed via maven). I have restarted and created a new project from scratch. This time you'll see the file .idea/libraries/KotlinJavaRuntime.xml, which is exactly what is referenced from the iml file. The .idea folder is very magic. For me the confusion is that modules in IntelliJ are not really isolated from the project, they share - like in this case - the .idea folder.
I hope this helps also other users.

If you created the kotlin-file yourself, you have to tell IntelliJ that it should run this file.
Normally shows a run icon next to your main method.
run button/icon
Option 2: Right Click on the file containing the main method and see if there is a run this file option.
Option 3: add run config manually
Click add config which should be on the left of the run button (don't mind that it is disabled)
Click + and choose Kotlin.
Set main class to MainKt which is the default for kotlin

Related

Executing post-build step Intellij IDEA CE 2020.3?

I am using IntelliJ IDEA CE 2020.3 to build a simple JAR file. After the build, I'd like to copy the created JAR to a library directory.
I am using the Ant plugin that comes bundled with the IDE. I can't seem to find the underlying Ant build/control files that make the whole thing work. I assume Ant uses the .XML files that are part of the IDE's project settings, but this is unclear.
In any case, is there a way to add the "copy" step that I mention above?
Do I have to either use the built-in Ant or take it over completely myself?
Can I edit the default that ships with the IDE?
All,
So after some experimenting, I found that if I manually create the build.xml file, I can execute post-build steps. For my example here, I created the following, simple build.xml and added it to the top-level IntelliJ project directory (where the .iml file lives):
build.xml (manually created)
<project name="mylib" default="copy-file">
<target name="copy-file">
<copy file="out/artifacts/mylib_JAR/mylib.jar" tofile = "./mylib.jar" />
</target>
</project>
Note that the directories are relative to the project directory.
IntelliJ IDEA enabled me to add the copy-file task to augment the default, built-in build. To configure your tasks via the IDE, open the Ant tool window via the View/Tool Windows/Ant main menu item.
I hope this helps someone out there!

JavaFX - (IntelliJ) FXML loader (NullPointerException: Location is required)

I get a NullPointerException for FXML loader when I execute the below in IntelliJ, but not in Eclipse IDE
Parent root = FXMLLoader.load(getClass().getResource("/view/MainView.fxml"));
Please note, the project is the same (not copy) opened in the 2 IDE's simultaneously, since it is the same project opened, the file / folder structure is the same. My search in this forum & on google for this specific issue so far has drawn blanks.
Seek guidance as to what settings I need to check / change in the IntelliJ to get it working?
Managed to resolve this finally.
I re-imported the project to IntelliJ as a Gradle project & added the steps in Gradle Build file as mentioned in the link earlier.
The same error occured to me. My project used to be a Maven project, but I tried to remove all of those components. It appears I didn't quite succeed in doing so.
I noticed that the fxml files were not properly copied into the target directory.
In .idea/compiler.xml I changed the following line:
<profile name="Maven default annotation processors profile" enabled="true">
to now read:
<profile name="Maven default annotation processors profile" enabled="false">
This fixed the problem and allowed the FXMLLoader to find the fxml file.

Where is the "jrebel JAR-file" in the my WAR-file?

I want to use jrebel with intellij IDEA and JBOSS AS7.
(have a web application(so have WAR)).
By apache-ANT , build my-WAR and deploy it under JBOSS AS.
I know how introduce any changes of classes or resources to jrebel in the my-WAR (If I'm not mistaken!) , as follows:
(In rebel.xml)
<classpath>
<dir name="D:/project/myProject/out/production/myProject">
</dir>
</classpath>
<web>
<link target="/">
<dir name="D:/project/myProject/resources">
</dir>
<dir name="D:/project/myProject/view">
</dir>
</link>
</web>
But, really, "jerebel jar-file" Where is the my-WAR?
in => "warFile >WEB-INF > lib"?I did not see it.
please help me.
jrebel.jar is packaged inside the JRebel plugin for IntelliJ IDEA. It doesn't have to be deployed with the WAR itself. JRebel plugin will set the correct JVM parameters to the command line when you start via "Run with JRebel" or "Debug with JRebel":
-javaagent:/path/to/jrebel.jar
UPDATE: the newer versions of JRebel are configured using -agentpath JVM option instead:
-agentpath:${JREBEL_HOME}/lib/<platform-specific-binary>
See the documentation reference of the correct settings.
You don't have to do it yourself if you start the server from the IDE. If you start the server from the command line then you would have to add the JVM argument yourself with the correct path to jrebel.jar as described here: http://manuals.zeroturnaround.com/jrebel/standalone/launch-from-command-line.html#jboss-7-x
Java agents intercept class loading and thus have to be loaded before other classes. As you might have guessed, jrebel.jar is a Java agent and therefor nothing requires it to be packaged inside a WAR.
Instead, rebel.xml, the configuration file, has to be packaged in the WAR, in WEB-INF/classes directory. JRebel uses rebel.xml to detect, where the compiled classes and resources are. So when the application is deployed, JRebel finds rebel.xml configuration file and won't load the application classes from WAR itself, but instead it will use the path that is specified in that rebel.xml file. This is why rebel.xml has to be inside the war, as you may also start the server from command line instead of the IDE.

My plugin doesn't show up in Eclipse "Show view"

I created my first Eclipse plugin.
Plugin has one view.
When I ran my plugin project(Overview>Testing section>Launch an Eclipse application), it shows in Eclipse workbench and "Show view" menu.
Then I copy & paste exported plugin jar file to Eclipse's plugins folder.
Unfortunately I can't found my plugin view in Show view menu.
I also paste dropins and dropins/plugins folder.
But it doesn't works.
OS : Windows 7
Eclipse : Eclipse Java EE IDE for Web Developers [Kepler Service Release 2]
plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="String Table"
id="com.andcontinue.stringtable">
</category>
<view
name="String Table"
icon="icons/sample.gif"
category="com.andcontinue.stringtable"
class="com.andcontinue.stringtable.views.StringTable"
id="com.andcontinue.stringtable.views.StringTable">
</view>
</extension>
<extension
point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
</contexts>
</extension>
</plugin>
I don't know why plugin be not displayed in Show view.
Other references
build.properties
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
.,\
contexts.xml,\
icons/,\
META-INF/,\
.classpath,\
src/,\
MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: String Table
Bundle-SymbolicName: (MyPackage);singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: (MyPackage).Activator
Bundle-Vendor: Vendor
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.8.101",
org.eclipse.jdt.core;bundle-version="3.9.2"
Bundle-ActivationPolicy: lazy
Export-Package: (MyPackage),
(MyPackage).views
Import-Package: org.eclipse.jface.text
Bundle-ClassPath: .
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Please help me.
Thank you.
Some Clues:
Check after installation of plugin whether is it appearing in Running Platform. Go to Window > Preferences> Plugin Development > Target Platform select Running Platform click on Edit and check your plugin. The presence shows that Platform detected your plugin but there may be some issues in your code.
Note: I am assuming you used the Running platform as your target.
Instead of directly copying the jar into folder. Install this plugin via GUI.
Export your plugin to an external folder or to an archive file. Go to Help > Install New Software... Click on Add button then select a local folder or archive file. If there were some problems exists while exporting then this installer displays this.
This may also happen if the plugin you are using expects latest version of some library or compiler in your system. In my case, I was trying to install SonarLint plugin and although installation was successful, I could not see it in View because it only supported Java11 or above. You can check out further details of it in my answer here

How to assign sources to Ivy library in IntelliJ IDEA?

I created a Webapp with an Ant/Ivy build using Spring framework and imported the project into IntelliJ IDEA. Using the IvyIDEA plugin the dependencies are resolved and a library with the jars is created automatically by the plugin.
How can I assign the sources (they are downloaded and stored in the ivy cache) to the Idea library so I can just click on a class of a dependency to browse the source?
To see ivy's cache libs I did these steps:
1) Add library folder (Choose Java from + menu):
2) "cache" item will be added to libraries. Choose all modules of your project that should now see "cache" library (you could also add inside 'dependency' tab on each module)
3) now you should tell intellij to check recursively inside cache folder. To do this you must edit a file as follows:
File is located in your project folder under .idea/libraries/cache.xml
<component name="libraryTable">
<library name="cache">
<CLASSES>
<root url="file://$USER_HOME$/.ivy2/cache" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$USER_HOME$/.ivy2/cache" recursive="true" />
</library>
</component>
recursive property must be set to 'true'
It has to be explicitly enumerated in ivy.xml (at least in my Idea 11.1.5), i.e. sources are not shown for packages resolved as dependency of packages stated in ivy.xml. After introducing it is necessary to refresh modules (Tools->IvyIdea->resolve for ...).
See also:
https://code.google.com/p/ivyidea/issues/detail?id=92