简体   繁体   中英

Can NetBeans run Kotlin?

This is more to see if Kotlin can really work in NetBeans, even if it requires jumping through too many hoops to be practical. If I really do need to use Kotlin, I have IntelliJ.

Supposedly Kotlin can be used in Eclipse and NetBeans. It looks like you can write Kotlin in NetBeans all you want, but it's not gonna run at all.

I installed the Kotlin for NetBeans plugin, and it seems to work. It has all the hints and syntax highlighting that one would expect. But when it comes to actually running something written in Kotlin, NetBeans seems to be completely incapable. I also had trouble importing JUnit into a Kotlin test class.

But the first thing to accomplish before anything else is Hello World. I tried a couple of simple Hello Worlds. The Java Hello World runs. The Kotlin Hello World doesn't. I even tried to run it through the Scala REPL with much the same results.

From HelloWorld.kt (this is only missing the license header reminder and the generated Javadoc):

package basicexerciseskotlin

fun main(args: Array<String>) = println("Hello, world, from Kotlin!")

My first draft of this had a bunch of errors and warnings, and the hints helped me get it to this form, so now I have a green indicator. But Run > Run File is grayed out, and the keyboard shortcut does nothing.

Then I thought maybe I could call HelloWorld.main() from a Java class. To figure out how to do that, I made a similar project in IntelliJ. I copied what I came up with in IntelliJ to NetBeans, but I had to comment out the line that calls on HelloWorldKt .

From BasicExercisesKotlin.java (the main class in the project, as far as NetBeans is concerned):

package basicexerciseskotlin;

public class BasicExercisesKotlin {

    public static void main(String[] args) {
        System.out.println("Hello world, from Java!");
        String[] kArgs = {""};
//        HelloWorldKt.main(kArgs);
    }

}

In IntelliJ:

/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/bin/java ...
Hello, world, from Java!
Hello, world, from Kotlin!

Process finished with exit code 0

But NetBeans can't find the symbol HelloWorld nor HelloWorldKt .

In the Scala REPL:

scala> basicexerciseskotlin.BasicExercisesKotlin.main(null)
Hello world, from Java!

scala> basicexerciseskotlin.HelloWorldKt.main(null)
java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
  at basicexerciseskotlin.HelloWorldKt.main(HelloWorld.kt)
  ... 28 elided
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
  at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 29 more

Just in case the null was a problem:

scala> val kArgs = Array("")
kArgs: Array[String] = Array("")

scala> basicexerciseskotlin.HelloWorldKt.main(kArgs)
java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
  at basicexerciseskotlin.HelloWorldKt.main(HelloWorld.kt)
  ... 28 elided

Maybe the plugin neglected to resolve some necessary paths?

I did think about scrutinizing the bytecode generated by IntelliJ, but I don't know enough about that to make sense of it.

There are two issues about that topic which show that there is promosing progress:

The accepted PR is a good sign that it could soon land in the official list of plug ins.

To run kotlin on netbeans download this plugin from the site or write kotlin in the tools section -> plugin

Kotlin PLug-In Netbeans

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM