FreeBSD 支持 OracleJDK 与 OpenJDK。OracleJDK 不是原生支持,需要使用 Linux 二进制兼容层。参见 。
JDK
OracleJDK
java/linux-oracle-jdk18 不可用,太久没更新,兼容层所需链接已经失效了。
=> Attempting to fetch http://distcache.FreeBSD.org/ports-distfiles/centos/libXtst-1.2.3-1.el7.i686.rpm
fetch: http://distcache.FreeBSD.org/ports-distfiles/centos/libXtst-1.2.3-1.el7.i686.rpm: No error: 0
=> Couldn't fetch it - please try to retrieve this
=> port manually into /usr/ports/distfiles/centos and try again.
*** Error code 1
Stop.
make[1]: stopped in /usr/ports/x11/linux-c7-xorg-libs
*** Error code 1
Stop.
make: stopped in /usr/ports/java/linux-oracle-jdk18
参考文献
OpenJDK
查看支持的版本:
root@ykla:~ # pkg search -o jdk
java/bootstrap-openjdk11 Java Development Kit 11
java/bootstrap-openjdk17 Java Development Kit 17
java/bootstrap-openjdk8 Java Development Kit 8
java/openjdk11 Java Development Kit 11
java/openjdk11-jre Java Runtime Environment 11
java/openjdk17 Java Development Kit 17
java/openjdk17-jre Java Runtime Environment 17
java/openjdk18 Java Development Kit 18
java/openjdk19 Java Development Kit 19
java/openjdk20 Java Development Kit 20
java/openjdk21 Java Development Kit 21
java/openjdk22 Java Development Kit 22
java/openjdk23 Java Development Kit 23
java/openjdk8 Java Development Kit 8
java/openjdk8-jre Java Runtime Environment 8
comms/rxtx Native interface to serial ports in Java
以 java/openjdk23 为例:
安装 openjdk23
# pkg ins openjdk23
或者
# cd /usr/ports/java/openjdk23
# make install clean
查看版本:
root@ykla:/ # java -version
openjdk version "23.0.2" 2025-01-21
OpenJDK Runtime Environment (build 23.0.2+7-1)
OpenJDK 64-Bit Server VM (build 23.0.2+7-1, mixed mode, sharing)
勾选 Babel Language Packs in Chinese (Simplified)。点击 Next。
点击 Next。
同意协议:
这里最好先随便点一下底部,再全选,否则会卡死。
重启即可:
参考文献
HelloWorld
点击 创建 Java 项目,项目名 test。
右键创建一个 包,再创建一个 java 类,名称 test。
写入以下内容
package test;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
点击绿色三角,即可看到输出
参考文献
IntelliJ IDEA
安装 IntelliJ IDEA Ultimate
# pkg ins intellij-ultimate
或
# cd /usr/ports/java/intellij-ultimate
# make install clean
查看安装后说明
root@ykla:~ # pkg info -D intellij-ultimate
intellij-ultimate-2024.3.1.1:
On install:
There is a native (faster) file watching support backed by kqueue which is
enabled by default. If you encounter problems with watching large
trees, you can disable it by adding the following property via the menu
entry Help -> Edit Custom Properties...
idea.filewatcher.disabled=true