Environment variable setup in mac for running a java application - macos

I am trying to setup a environment variable in OS X Yosemite. i am using zsh.
i added
export NEW_HOME=/Users/k/app/
and then loaded the file with
source .profile or source .bash_profile
but when i restart the terminal it goes away. Then i added this to .zshrc file. It works. I can get the environment variable from terminal now. But the java application which requires this ENV value is not getting.
I really do not understand whats going on. Can u help me?

Its solved by creating a environment.plist file in Library/Launchctl and seting the setenv inside string.
~/Library/LaunchAgents/local.launchd.conf.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.launchd.conf</string>
<key>ProgramArguments</key>
<array>
<string>setenv NEW_HOME /Users/k/app/</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
And after restating the Mac it started working.

Related

OSX asdf Launch Daemon Does Not Have Access to Languages

I have a launch daemon plist that runs a python script. The problem is that it is unable to run the script because it does not have access to python.
I am trying to make a launch daemon to change mac address (https://github.com/feross/SpoofMAC)
Here is the plist file in /Library/LaunchDaemons:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>MacSpoof</string>
<key>ProgramArguments</key>
<array>
<string>/Users/username/.asdf/shims/spoof-mac.py</string>
<string>randomize</string>
<string>en0</string>
</array>
<key>StandardOutPath</key>
<string>/Users/username/Projects/MAC/out.log</string>
<key>StandardErrorPath</key>
<string>/Users/username/Projects/MAC/err.log</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The Error Log reads:
No version is set for command spoof-mac.py
Consider adding one of the following versions in your config file at
python 3.11.1
My tool_version does include Python, how can I make this work?
Okay, I kinda got it working. I moved the plist file from /Library/LaunchDaemons to /Library/LaunchAgents and it works because LaunchAgents run after the user is logged in. It's not exactly what I wanted, but it works.

Coverage file is not getting generated using bullseye with XCode

I am trying to integrate BullsEye 8.14.0 with Xcode 10.12. Following are the steps that I followed:
mkdir -p $HOME/Library/LaunchAgents
2.Create the file $HOME/Library/LaunchAgents/BullseyeCoverage.plist with contents like below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>BullseyeCoverage</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>COVFILE</string>
<string>path</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Path I have given as $HOME/Desktop/BEC/test123.cov and also tried with Users/myUserName/Desktop/BEC/test123.cov
Add an export command like shown below to the file $HOME/.bash_profile.
export COVFILE=path
Added export PATH=$PATH:/Applications/BullseyeCoverage/bin, in .bash_profile as the first entry.
Then built the xcode project as usual.
Followed the document https://www.bullseye.com/help/tool-xcode.html, in short.
But after doing all this, I should be seeing a test123.cov file generated after the successful build with all the APIs listed, which I couldn"t see.
Am I missing anything?

Launchd PATH issue with TeamCity

I recently asked this question, and got everything working appropriately. The build agent is launching, RAM disk is being created.
It seems that there is an issue with the PATH environment variable. When I run the same command from terminal, all my builds build fine. When it is launched from launchd, I get errors like "can not find mono" or "can not find nuget" both of those paths are environment variables.
How can I modify the PATH variable for a launchd file?
Here is my Launch Agent:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.datafinch.teamcity</string>
<key>Program</key>
<string>/Users/administrator/startup.sh</string>
<key>RunAtLoad</key>
<true/>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>
And here is the script startup.sh
#!/bin/bash
setenv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
DISK=`/usr/bin/hdiutil attach -nobrowse -nomount ram://16777216`
/usr/sbin/diskutil erasevolume HFS+ "RamDiskCache" $DISK
/Users/administrator/buildAgent/bin/agent.sh start
When I set the PATH explicitly in my startup.sh it still doesnt work.

M2_HOME not working in IntelliJ on OSX 10.10.1 Yosemite

ive tried :
echo $M2_HOME
/usr/local/apache-maven-3.2.3
seemd like M2_HOME is set
and the file /etc/launchd.conf looks like this:
setenv $M2_HOME /usr/local/apache-maven-3.2.3
ive restarted the mac and still nothing works ...
any idea ?
checkout :
"and the file /etc/launchd.conf looks like this:"
change :
setenv $M2_HOME /usr/local/apache-maven-3.2.3
to
setenv M2_HOME /usr/local/apache-maven-3.2.3
Create new file /Library/LaunchDaemons/setenv.M2_HOME.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>setenv.BAR</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>M2_HOME</string>
<string>/opt/local/share/java/apache-maven-3.1.1</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
Then restart the computer, or execute
launchctl load -w /Library/LaunchDaemons/setenv.M2_HOME.plist
Relaunch IDEA, and it picks up MAVEN_HOME. Tested on Yosemite 10.10.3.
Source: http://lajosd.blogspot.be/2015/06/place-following-content-enhance-it-to.html

WatchPaths not working for file added in OSX

I am using MAC OSX 10.6.8.
I would like to apply a script that copy a backup file when I find there is a file named temp.txt.
Here is my plist in /Library/LaunchAgents
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.lion.backupfile</string>
<key>ProgramArguments</key>
<array>
<string>/Users/lion/q_backup.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Users/lion/temp.txt</string>
</array>
</dict>
</plist>
I find the script only be excuted when file being removed or modified.
How could I excute the script when there is a file exist in the path?
There is no such key in launchd.plist.
WatchPaths will work if any one of the listed paths are modified.
QueueDirectories will run your script whenever there's a file in that directory.

Resources