VSCode中的Java,如何设置编译后的 .class 文件的存储路径?

huangapple go评论95阅读模式
英文:

VSCode java how do I set the path for the compiled .class files to go?

问题

我正在使用VScode中的Java测试运行器扩展,希望它将我的类编译到特定的文件夹中。我找到了更改在实际运行已编译的.class文件时的-cp的设置,但整个过程仍然失败,因为该扩展将.class文件构建在一个深藏在其appdata文件夹中的不明显的临时文件夹中。

我希望它能将我的.java类编译到项目中的一个文件夹中,以便我可以在那里找到它们。我已经试图在谷歌上搜索这个问题,但要么我不知道我在说什么,要么以前没有人遇到过这个问题。

提前感谢你的帮助。

英文:

I'm using the Java Test Runner extension in VScode, and I want it to compile my classes to a specific folder. I found the setting to change the -cp when actually running the compiled .class files, but the whole thing still fails since the extension builds the .class files in an obscure temporary folder deep in it's appdata folder.

I would like it to compile my .java classes into a folder I have within my project, so that I can have them there. I have tried googling the sh*t out of this and either I have no idea what I'm saying or noone has ever had a problem with this before.

Thanks in advance for the help.

答案1

得分: 2

这是一个晚回答,但我刚遇到了这个问题,所以我希望能帮助其他人。

截至2021年2月4日,Visual Studio Code 的 Java 语言支持扩展中现已添加了一个设置,您可以在其中指定编译后的 .class 文件的输出目录。如果您正在使用 VS Code 运行 Java,我几乎可以肯定您已安装了这个扩展。

只需打开您的 VS Code 设置,然后搜索 java.project.outputPath。正如您将注意到的,它指出此设置仅适用于工作区设置,不适用于用户设置。因此,在单击 在 settings.json 中编辑 之前,务必切换到工作区选项卡。这将编辑项目 .vscode 文件夹中的 settings.json 文件。

此外,请注意,这对于使用 Maven/Gradle 管理的项目无效。但对于简单项目来说,它非常有用。

对于好奇的人:这是添加此功能到扩展的 GitHub 拉取请求的链接(还附有功能操作的漂亮 GIF):https://github.com/redhat-developer/vscode-java/pull/1694

英文:

This is a late answer, but I just ran into this so I hope it helps others.

As of Feb 4, 2021 there is now a setting for the Java Language Support for VS Code extension, where you can specify the output directory for compiled .class files. If you're using VS Code to run Java I'm almost certain you'd have this extension installed.

Simply open your VS Code settings and search for java.project.outputPath. As you'll notice, it states this setting only applies for Workspace settings, not User settings. So make sure to switch to the Workspace tab before clicking Edit in settings.json. This will edit the settings.json file in your projects .vscode folder.

VSCode中的Java,如何设置编译后的 .class 文件的存储路径?

Also note this doesn't work for projects managed with Maven/Gradle. It's great for simple projects though.

For the curious: link to the GitHub pull request where the feature was added to the extension (also has a neat gif of feature in action): https://github.com/redhat-developer/vscode-java/pull/1694

答案2

得分: 0

在"添加库和JAR文件"部分。

英文:

https://blog.usejournal.com/visual-studio-code-for-java-the-ultimate-guide-2019-8de7d2b59902

Under "Adding Libraries and JARs"

答案3

得分: 0

首先,
你可以在环境变量部分创建一个CLASSPATH位置,在设置好路径位置之后。

另外,人们通常会错误地安装一个代码运行器,用于编译和运行所有语言,所以如果你通过右上方的运行按钮运行你的Java代码,
然后点击旁边的下拉菜单,点击“运行Java”按钮,我想你的代码应该会正常运行的。(如果你已经单独下载了Java运行器扩展)

希望这能帮到你!

英文:

First of all,
you can create a CLASSPATH location in your environment variable section, after you set your path location.

Also, what people usually mistake is that they install a code runner used to compile and run all the languages, so if you are running your java code through the top-right run button,
then click on the drop down menu beside it and click the "run java" button and I guess then your code will run just fine.(if you have downloaded java runner extension separately)

I hope this helps!

huangapple
  • 本文由 发表于 2020年8月26日 01:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63583862.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定