【原创】MacOS brew install wildfly(Jboss)
环境信息
OS:
MacOS Catalina 10.15.3
brew:
$ brew --version
Homebrew 2.2.9
Homebrew/homebrew-core (git revision c735; last commit 2020-03-04)
Homebrew/homebrew-cask (no git repository)
必要依赖
由于 Wildfly(Jboss) 是用于运行 Java Web Applications 的容器。因此,必要的依赖就是 JDK。下方的 Wildfly 官网有不同版本需要的 JDK 版本映射表
https://docs.wildfly.org/
注:使用 brew 安装 wildfly 时,brew 会自动安装对应的 openjdk 的依赖。即使你已经安装了 JDK 也如此。
我的 JDK 版本:
$ java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
安装步骤
1、brew search
使用 brew search 查看是否有可用的 wildfly 包,从下方内容可看出有 wildfly 相关的包 wildfly-as。如果你不确认 brew 库中是否有 wildfly 的程序,此步骤不建议跳过。
$ brew search wildfly
==> Formulae
wildfly-as
2、brew install
使用 brew install wildfly-as 安装
$ brew install wildfly-as
==> Installing dependencies for wildfly-as: openjdk
==> Installing wildfly-as dependency: openjdk
==> Downloading https://homebrew.bintray.com/bottles/openjdk-13.0.2+8_2.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/65/65adca036393f528e3830cab8b0aafec94be870de087d94cfe098fd593517307?__gda__=exp=1583350655~hmac=ced7208a5c8e76c115201b07eb06c773
######################################################################## 100.0%
==> Pouring openjdk-13.0.2+8_2.catalina.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because it shadows the macOS `java` wrapper.
If you need to have openjdk first in your PATH run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
==> Summary
🍺 /usr/local/Cellar/openjdk/13.0.2+8_2: 631 files, 314.6MB
==> Installing wildfly-as
==> Downloading https://download.jboss.org/wildfly/18.0.1.Final/wildfly-18.0.1.Final.tar.gz
######################################################################## 100.0%
==> Caveats
The home of WildFly Application Server 18.0.1.Final is:
/usr/local/opt/wildfly-as/libexec
You may want to add the following to your .bash_profile:
export JBOSS_HOME=/usr/local/opt/wildfly-as/libexec
export PATH=${PATH}:${JBOSS_HOME}/bin
To have launchd start wildfly-as now and restart at login:
brew services start wildfly-as
Or, if you don't want/need a background service you can just run:
/usr/local/opt/wildfly-as/libexec/bin/standalone.sh --server-config=standalone.xml
==> Summary
🍺 /usr/local/Cellar/wildfly-as/18.0.1.Final_1: 1,586 files, 211.6MB, built in 2 minutes 48 seconds
==> Caveats
==> openjdk
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because it shadows the macOS `java` wrapper.
If you need to have openjdk first in your PATH run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
==> wildfly-as
The home of WildFly Application Server 18.0.1.Final is:
/usr/local/opt/wildfly-as/libexec
You may want to add the following to your .bash_profile:
export JBOSS_HOME=/usr/local/opt/wildfly-as/libexec
export PATH=${PATH}:${JBOSS_HOME}/bin
To have launchd start wildfly-as now and restart at login:
brew services start wildfly-as
Or, if you don't want/need a background service you can just run:
/usr/local/opt/wildfly-as/libexec/bin/standalone.sh --server-config=standalone.xml
上面安装信息也可看出 brew 会安装依赖的 openjdk 版本。这里安装的版本如下:
wildfly:
18.0.1.Final_1
openjdk:
openjdk-13.0.2+8_2
修改配置
1、配置 openjdk PATH
如果你想要优先使用 openjdk 的话,可以做如下配置(如果有已安装的 JDK 则可不必配置)。在命令行运行如下命令进行配置。(可选)
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc
2、配置编译变量
配置 c/c++ 编译的环境变量(可选)
echo 'export CPPFLAGS="-I/usr/local/opt/openjdk/include"' >> ~/.zshrc
3、配置到 java wrapper
由于 MacOS 采用了的 java wrapper 来管理系统中的不同版本的 JDK,而 brew 安装的 openjdk 默认没有注册到 MacOS 的 java wrapper,可以使用如下命令配置(可选)
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
4、配置 JBOSS
可以将 jboss 的安装目录配置到用户环境变量中,便于操作 jboss。命令行执行如下命令(可选,建议配置)
echo 'export JBOSS_HOME=/usr/local/opt/wildfly-as/libexec' >> ~/.bash_profile
echo 'export PATH=${PATH}:${JBOSS_HOME}/bin' >> ~/.bash_profile
5、使配置的环境变量生效
命令行执行如下命令使配置生效
source ~/.zshrc
source ~/.bash_profile
验证安装
1、启动服务
(1) brew 后台运行
brew services start wildfly-as # 后台运行并注册到开机自启服务
brew services stop wildfly-as # 停止后台运行的 wildfly 服务
brew services run wildfly-as # 后台运行且不注册到开机自启服务
brew services restart wildfly-as # 重启服务
示例:
$ brew services start wildfly-as
==> Successfully started `wildfly-as` (label: homebrew.mxcl.wildfly-as)
(2) 验证后台进程
$ ps -ef | grep wildfly
501 40784 1 0 4:34AM ?? 0:00.01 /bin/sh /usr/local/opt/wildfly-as/libexec/bin/standalone.sh --server-config=standalone.xml
501 40837 40784 0 4:34AM ?? 0:25.93 /usr/local/opt/openjdk/bin/java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED -Dorg.jboss.boot.log.file=/usr/local/opt/wildfly-as/libexec/standalone/log/server.log -Dlogging.configuration=file:/usr/local/opt/wildfly-as/libexec/standalone/configuration/logging.properties -jar /usr/local/opt/wildfly-as/libexec/jboss-modules.jar -mp /usr/local/opt/wildfly-as/libexec/modules org.jboss.as.standalone -Djboss.home.dir=/usr/local/opt/wildfly-as/libexec -Djboss.server.base.dir=/usr/local/opt/wildfly-as/libexec/standalone --server-config=standalone.xml
(3) 使用 jboss 命令前台运行
/usr/local/opt/wildfly-as/libexec/bin/standalone.sh --server-config=standalone.xml
brew services 用法参考:
https://github.com/Homebrew/homebrew-services
如果 MacOS 10.15.3 出现 Error: Unknown command: services 的错误,则可以如下命令解决:
brew update-reset
参考:
https://github.com/Homebrew/homebrew-services/issues/206
3、访问服务
浏览器输入 http://localhost:9090 验证是否能访问,页面显示正常则 wildfly 通过 brew 安装完成。
附录
参考:
https://javavolker.wordpress.com/2014/02/15/installing-wildfly-on-mac-os-x/
近期评论