如何在Kotlin中运行已编译的类文件? [英] how to run compiled class file in Kotlin?

查看:220
本文介绍了如何在Kotlin中运行已编译的类文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jetbrains提供了一些文档,但是我找不到如何运行Kotlin的编译类文件.

Jetbrains provides some documentation but I can't find how to run compiled class file of Kotlin.

hello.kt:

fun main(args : Array<String>) {
  println("Hello, world!")
}

编译:

$ kotlinc -out dist -src hello.kt
$ ls dist
namespace.class
$ java dist/namespace
Exception in thread "main" java.lang.NoClassDefFoundError: dist/namespace (wrong name: namespace)
$ java -jar /usr/local/kotlin/lib/kotlin-runtime.jar
Failed to load Main-Class manifest attribute from
/usr/local/kotlin/lib/kotlin-runtime.jar 

如何运行Kotlin程序?

How to run Kotlin program?

推荐答案

我们遇到了同一个程序,并在此处将我们的解决方案写了博客:

We ran into the same program and blogged our solution here: http://blog.ocheyedan.net/blog/2012/02/19/running-kotlin-code/

基本上,您只需要使用-cp和'namespace'的主类来调用java.从您的问题来看,Java调用看起来像这样:

Basically you just need to invoke java with the -cp and the main class of 'namespace'. From your question, the java invocation would look something like this:

java -cp /usr/local/kotlin/lib/kotlin-runtime.jar:dist/namespace.class namespace

这篇关于如何在Kotlin中运行已编译的类文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆