java - 如何设置 VSCode 以使用 Kotlin 和 Java?
问题描述
我刚刚开始学习如何使用 Kotlin 进行编码,为此,我正在尝试配置 VSCode(版本 1.61),因为它是我的主要 IDE。
我正在使用具有以下特点的电脑:
- 静态主机名:pop-os
- 操作系统:Pop!_OS 21.04
- 内核:Linux 5.13.0-7614-generic
- 架构:x86-64
我已经验证我安装了 java、kotlin 和 kotlic:
$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2, mixed mode, sharing)
$ kotlin -version
Kotlin version 1.5.31-release-548 (JRE 11.0.11+9-Ubuntu-0ubuntu2)
$ kotlinc -version
info: kotlinc-jvm 1.5.31 (JRE 11.0.11+9-Ubuntu-0ubuntu2)
在 Vscode 中,我安装了以下扩展:
- Mathiasfrohlich 的 Kotlin 语言
- 韩君的代码跑者
- Microsoft 的 Java 扩展包
- 微软的 Java 调试器
- Red Hat 对 Java 的语言支持
完成所有这些之后,我创建了一个文件夹,其中包含~/Learning/Kotlin/HelloWorld/
一个简单的 kotlin 文件"helloworld.kt"
,其中包含以下代码:
fun fun main(args: Array<String>) {
println("Hello Kotlin")
}
在尝试运行代码时,我收到一个关于找不到 kotlinc 命令的错误,所以我在文件中添加了以下内容~/.bashrc
:
export KOTLIN_HOME=/home/usr/.sdkman/candidates/kotlin/current
export PATH=$PATH:$KOTLIN_HOME/bin
但是,现在我收到以下错误:
[Running] cd "/home/mantress31/Documents/Manuel/Aprendizaje/Kotlin/Hello World/" && kotlinc helloworld.kt -include-runtime -d helloworld.jar && java -jar helloworld.jar
/home/usr/.sdkman/candidates/kotlin/current/bin/kotlinc: line 98: java: command not found
有人可以告诉我在配置所有这些时我是否做错了什么?和/或我还应该做些什么来解决这个问题?
解决方案
I do not know if this is the best way of solving the problem, but I managed to make it work by doing the following:
First, I installed Oracle's JDK following the instructions in this video: Installing Oracle JDK on Linux.
After that, I went to the .bashrc
file (In my pc it is located on the home folder), and added the following: export PATH=$PATH:$JAVA_HOME/bin
. After doing this, I reset the file with the source ~/.bashrc
.
The error in VSCode was fixed after doing this. Please let me know if there is a better way of doing this.
推荐阅读
- angular - Ionicons 版本 5 带角度
- javascript - 在 Nuxt 组件中访问 axios 返回的数组以循环
- html - Web 应用程序立即启动和停止
- vuejs2 - 使用 Vue 路由器从 Dropbox Oauth 重定向获取访问令牌
- wordpress - 是否可以使用 S3 持久化我的 ECS 容器存储?
- python-3.x - 从同级目录导入 - Python 3.7
- javascript - 如何使用 javascript 更改 iframe 内视频的播放速率/速度?
- python - 为什么我的数据无效?(serializer.is_valid() 返回 False)
- python - Tika 在 Windows 上通过 python 抛出 AttributeError
- rust - Rust 中的动态类型实体组件系统