前言
使用MAC idea2025.2 tomcat8 设置环境变量,启动失效问题解决
分析
网上说是zsh
和bash
命令问题,但是尝试多次覆盖文件,启动读取依然没用
MAC下~/.bash_profile无效
~/.bash_profile配置无问题,为何每次打开新的终端都需要source ~/.bash_profile 才可以生效呢?
shell
1
chsh -s /bin/bash
2
cd ~
ls .zshrc
vim .zshrc
写入:source ~/.bash_profile
:wq 进行关闭
bash_profile
每次打开都是空的,或者就算有,但是idea启动读取还是空的
原因
在 macOS 下,终端中的环境变量是通过 shell 配置文件(~/.zshrc 或 ~/.bash_profile)加载的
但是,IDEA 是通过 GUI 启动的,不会读取这些 shell 配置文件,也不会继承你在 Terminal 里设置的变量。
mac idea启动读取不到系统环境变量解决办法
文章要求进入这个文件,但是我查看了下,并没有,索性使用
shell
vim ~/Library/LaunchAgents/environment.plist
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>user.environment</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>setenv</string>
<string>key</string>
<string>value</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
解决
尝试这么多方案,也没解决,于是选择最基础的方法tomcat配置环境变量 ,这样启动读取的就是自己配置的