简体   繁体   English

"如何设置 VSCode 以使用 Kotlin 和 Java?"

[英]How do I set up VSCode to use Kotlin and Java?

I am just starting to learn how to code with Kotlin and for that, I am trying to configure VSCode (Version 1.61) as it is my main IDE.我刚刚开始学习如何使用 Kotlin 进行编码,为此,我正在尝试配置 VSCode(版本 1.61),因为它是我的主要 IDE。

I am using a pc with the following characteristics:我正在使用具有以下特点的电脑:

  • Static hostname: pop-os静态主机名:pop-os<\/li>
  • Operating System: Pop!_OS 21.04操作系统:Pop!_OS 21.04<\/li>
  • Kernel: Linux 5.13.0-7614-generic内核:Linux 5.13.0-7614-generic<\/li>
  • Architecture: x86-64架构:x86-64<\/li><\/ul>

    I have verified that I have java, kotlin and kotlic installed:我已经验证我安装了 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)<\/code><\/pre>

    In Vscode I have installed the following extensions:在 Vscode 中,我安装了以下扩展:

    • Kotlin Language by mathiasfrohlich Mathiasfrohlich 的 Kotlin 语言<\/li>
    • Code Runner by Jun Han韩君的代码跑者<\/li>
    • Extension Pack for Java by Microsoft Microsoft 的 Java 扩展包<\/li>
    • Debugger for Java by Microsoft微软的 Java 调试器<\/li>
    • Language Support for Java by Red Hat Red Hat 对 Java 的语言支持<\/li><\/ul>

      After doing all this I created a folder ~\/Learning\/Kotlin\/HelloWorld\/<\/code> with a simple kotlin file "helloworld.kt"<\/code> containing the following code:完成所有这些之后,我创建了一个文件夹~\/Learning\/Kotlin\/HelloWorld\/<\/code> ,其中包含一个简单的 kotlin 文件"helloworld.kt"<\/code> ,其中包含以下代码:

       fun fun main(args: Array<String>) { println("Hello Kotlin") }<\/code><\/pre>

      When trying to run the code, I received an error about not finding the kotlinc command, so I added the following to the ~\/.bashrc<\/code> file:在尝试运行代码时,我收到一个关于找不到 kotlinc 命令的错误,因此我将以下内容添加到~\/.bashrc<\/code>文件中:

       export KOTLIN_HOME=\/home\/usr\/.sdkman\/candidates\/kotlin\/current export PATH=$PATH:$KOTLIN_HOME\/bin<\/code><\/pre>

      However, now I am getting the following error:但是,现在我收到以下错误:

       [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<\/code><\/pre>

      Could someone tell me if I have done something wrong while configuring all this?有人可以告诉我在配置所有这些时我是否做错了什么? And\/Or What else should I do to fix this problem?和\/或我还应该做些什么来解决这个问题?

      "

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 .首先,我按照以下视频中的说明安装了 Oracle 的 JDK:在 Linux 上安装 Oracle JDK

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 .之后,我转到.bashrc文件(在我的电脑中它位于主文件夹中),并添加以下内容: export PATH=$PATH:$JAVA_HOME/bin After doing this, I reset the file with the source ~/.bashrc .执行此操作后,我使用source ~/.bashrc重置文件。

The error in VSCode was fixed after doing this.执行此操作后,VSCode 中的错误已修复。 Please let me know if there is a better way of doing this.请让我知道是否有更好的方法来做到这一点。

也许我在另一个线程中对类似问题的回答即将到来=> https://stackoverflow.com/a/70944315/7104589

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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