简体   繁体   English

如何在 NetBeans 8.2 中设置默认 Java 平台?

[英]How can I set the default Java platform in NetBeans 8.2?

I want to set the default Java Platform which is used to build my projects in NetBeans 8.2 (netbeans_jdkhome).我想设置用于在 NetBeans 8.2 (netbeans_jdkhome) 中构建我的项目的默认 Java 平台。

Prior versions allowed me to do that.以前的版本允许我这样做。 See this answer . 看到这个答案

The only problem is that I want to set this platform to be 1.7 (instead of current 1.8), but NetBeans 8.2 requires to run on 1.8, so I cannot have 1.7 as the default Java Platform.唯一的问题是我想将此平台设置为 1.7(而不是当前的 1.8),但 NetBeans 8.2 需要在 1.8 上运行,所以我不能将 1.7 作为默认 Java 平台。

Is there a way to override it?有没有办法覆盖它?

You can get your default JDK by: Tools - Java Plattforms . 您可以通过以下方式获取默认JDK: Tools - Java Plattforms There you can add all your JDKs and watch their bibs. 在那里,您可以添加所有JDK并观看他们的围兜。 If you want to change the default one you need to go the path: C:\\Program Files\\NetBeans 8.2\\etc and you need to change the netbeans.conf 如果要更改默认路径,则需要转到路径: C:\\ Program Files \\ NetBeans 8.2 \\ etc ,您需要更改netbeans.conf

In line 57 (in mine) you see something like this: 在第57行(我的)你看到这样的东西:

netbeans_jdkhome="C:\Program Files\Java\jdk1.8.0_66"

Change the Path to your wanted JDK and you´re finish. 将路径更改为您想要的JDK并完成。

Here a longer description. 这里有更长的描述。

For now, it appears there is no way to override it, here is NetBeans Help about Java Platform Manager: 目前,似乎没有办法覆盖它,这里是关于Java Platform Manager的Ne​​tBeans帮助:

Use to register different versions of the Java Development Kit (JDK) and other Java tools that your programs depend on. 用于注册不同版本的Java Development Kit(JDK)和程序所依赖的其他Java工具。 The dialog box lists all of your registered JDKs in the left pane and lists the JDK that the IDE is running on as the Default Platform. 该对话框在左窗格中列出了所有已注册的JDK,并将运行IDE的JDK列为默认平台。

So I'll have to change platform for each project because Netbeans 8.2 can not run with JDK 1.7 (so I can't set it as default platform). 因此,我必须为每个项目更改平台,因为Netbeans 8.2无法与JDK 1.7一起运行(因此我无法将其设置为默认平台)。

LenglBoy didn't even read my question, the same thing was done in the link I posted. LenglBoy甚至没有看过我的问题,在我发布的链接中也做了同样的事情。

There is a recent plugin that allows to right-click maven projects to set the JDK (still cannot set it by default). 有一个最近的插件允许右键单击maven项目来设置JDK(默认情况下仍然无法设置)。

There is no eclipse like default option. 没有像默认选项那样的eclipse。 You can set java platform for every imported project. 您可以为每个导入的项目设置java平台。 Change JRE in NetBeans project 在NetBeans项目中更改JRE

Here is how to set and change default JDK in NetBeans for Mac OS X users (tested with NetBeans IDE 12.5, should work with several other versions):以下是在 NetBeans 中为 Mac OS X 用户设置和更改默认 JDK 的方法(使用 NetBeans IDE 12.5 测试,应该适用于其他几个版本):

  • Close NetBeans关闭 NetBeans
  • Navigate to the file "netbeans.conf" (path is usually /Applications/NetBeans/Apache NetBeans 12.5.app/Contents/Resources/NetBeans/netbeans/etc/netbeans.conf )导航到文件“netbeans.conf”(路径通常是/Applications/NetBeans/Apache NetBeans 12.5.app/Contents/Resources/NetBeans/netbeans/etc/netbeans.conf
  • Open the file with TextEdit or another editor of your choice使用 TextEdit 或您选择的其他编辑器打开文件
  • In the document, search for the following line: #netbeans_jdkhome="path/to/jdk"在文档中,搜索以下行: #netbeans_jdkhome="path/to/jdk"
  • Uncomment the piece of code by deleting the hash sign: netbeans_jdkhome="path/to/jdk"通过删除井号取消注释这段代码: netbeans_jdkhome="path/to/jdk"
  • Change "path/to/jdk" with the path to the JDK you want to set as default JDK in NetBeans.将“path/to/jdk”更改为要在 NetBeans 中设置为默认 JDK 的 JDK 的路径。 Example: /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home示例: /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
  • Finally the crucial line of code should look like this: netbeans_jdkhome="/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home"最后,关键的代码行应如下所示: netbeans_jdkhome="/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home"
  • Save the file you've just edited.保存您刚刚编辑的文件。 The file was called netbeans.conf and it has to be the SAME name, saved in the SAME folder as before该文件名为 netbeans.conf 并且它必须是相同的名称,与以前一样保存在 SAME 文件夹中
  • Open NetBeans打开 NetBeans
  • Check if it worked: Go to Tools -> Java Platforms.检查它是否有效:转到工具 -> Java 平台。 On the left side you will see which JDK is set to default.在左侧,您将看到哪个 JDK 设置为默认值。

Hope this helped the mac users.希望这对mac用户有所帮助。

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

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