I'm trying to install a package using Brew, via my Java app (ie no terminal is used).
While my install command works as expected in the terminal, it doesn't work on my Java app. The error is error=2, No such file or directory, so I'm guessing the keyword brew is not recognized.
I'm running my command like this from Java: Runtime.getRuntime().exec("brew install somepackage").
Now I'm trying to find the path to brew so that I could try this: Runtime.getRuntime().exec({"/some/path/to/brew", "install somepackage"}).
My problem is that I don't know where brew is stored in my mac.
Anyone knows?
Thanks
you can run
which brew
on your command line to see the path to your brew binary.
It defaults to /usr/local/bin/brew.
The reason that the call from java does not work is probably caused by the unchanged PATH variable within java, that you changed in your ~/.bash_profile to include /usr/local/bin
Related
I am building a library on Mac Big Sur using Java 8 from Adoptium (Eclipse Temurin).
To install Java, I am using the following commands:
brew tap homebrew/cask-versions
brew install --cask temurin8
Then, I export JAVA_HOME like this:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
And it properly exports it. When I execute echo $JAVA_HOME, it returns:
/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home
However, while building the library, it tries to find JNI, and it is returning the following lines:
CMake Error at /usr/local/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find JNI (missing: JAVA_INCLUDED_PATH JAVA_INCLUDED_PATH2 AWT)
Is there anything else necessary to make this work on MacOS?
Notes:
I installed cmake using brew (brew install cmake).
I have already searched in Google and StackOverflow, and none of the proposed solutions worked (I have also checked the recommended similar questions while creating this one).
I checked the variable values in the FindJNI.cmake file and everything seems correct (it should find it).
In FindJNI.cmake, the value of JAVA_AWT_INCLUDE_DIRECTORIES is correct (/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/include), and jni.h is inside that directory. However, find_path(JAVA_INCLUDE_PATH 'jni.h' $(JAVA_AWT_INCLUDE_DIRECTORIES)) is not setting JAVA_INCLUDE_PATH properly.
I created a dummy project using find_path(TEST 'jni.h' '/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/include'), looking for jni.h and it works. TEST contains the correct value.
Thank you.
Edit:
This is the call to find_package:
find_package(JNI 1.7 REQUIRED)
I was finally able to solve this by setting the requested variables as flags for cmake. I just appended the following to my cmake call:
cmake ... -DJAVA_HOME=$(/usr/libexec/java_home -v 1.8) -DJAVA_INCLUDE_PATH=$(/usr/libexec/java_home -v 1.8)/include -DJAVA_INCLUDE_PATH2=$(/usr/libexec/java_home -v 1.8)/include/darwin -DJAVA_AWT_INCLUDE_PATH=$(/usr/libexec/java_home -v 1.8)/include
I have java installed and set up properly and works fine with the normal Windows Powershell. However, I'm trying to make java work with the ZSH terminal and I cannot get it to work.
My JAVA_HOME (in powershell) is set to this path:
C:\Program Files\Java\jdk-15.0.2
Im trying to add this line to my .zshrc file:
export JAVA_HOME=`/mnt/c/"Program Files"/Java/jdk-15.0.2`
but when i do source .zshrc it says permission denied to that file. Running sudo chmod doesnt seem to help either. Am i doing something wrong or missing some other line to add? Most tutorials for ZSH is on a Mac OS so i dont know if it differs being that im in windows...
The backticks are trying to "execute" that folder as a shell command.
Double quotes will store that variables as a string
export JAVA_HOME="/mnt/c/Program Files/Java/jdk-15.0.2"
But this doesn't guarantee that java command itself will work.
I have read a few other threads similar to this one on stack overflow, but I've been unable to solve my problem.
I am trying to install a package.
apt install libgnutls28-dev
however, I get the following error.
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/apt" (-1)
Other people have been able to solve this error by setting the java home environment variable in the terminal.
export JAVA_HOME=/Library/Java/Home
I have tried this, and then run apt install again, but recieved the same error:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/apt" (-1)
Any help is appreciated!
Hey I encountered this when trying to install libsndfile. Turns out I was reading their instructions for Debian/Ubuntu. apt isn't a thing on macosx. You'll want to use an alternative package installer like brew.
https://unix.stackexchange.com/questions/359219/error-when-using-apt-on-macos-sierra
export JAVA_HOME should point to the directory where the JDK or JRE is installed.
JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::") in a console or directly in .bashrc should do the trick under debian
I am trying to install JNetPcap and followed the instructions given at here. At step 12, I am unable to run the ant command and i see the error
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-6-sun/bin/java
As I am able to run Java classes from eclipse or from command line I don't think if it's a problem with JAVA_HOME.
echo $PATH shows
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun/bin
Kindly let me know if am missing something here.
thanks in advance
Neither running java from the command line or running eclipse will require JAVA_HOME to be set. However, the build procedure you are trying to use ant, and ant often does require JAVA_HOME to be set appropriately. (It actually depends on the version of ant that you are using. The use of JAVA_HOME is typically in the wrapper script for ant.)
Just set it.
JAVA_HOME should probably be set to /usr/lib/jvm/java-6-sun ... based on what you gave said PATH to.
However, it is also possible that the problem is that your PATH is incorrect. Or that you have (somehow) managed to get the owner/group/permissions on your Java install incorrect, such that the java command isn't executable.
Check that running java -version displays the installed Java version.
Repeat with /usr/lib/jvm/java-6-sun/bin/java -version.
I am having trouble finding where java is installed on my mac. I am trying to downgrade from java 1.8 to java 1.7.
When I run the command /usr/libexec/java_home it returns /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
but the trouble is when I go to the Library folder there is no Java folder. I've tried navigating there in terminal and it says -bash: cd: Java: No such file or directory
How can I get the Java folder to show? I was thinking maybe it is hidden. Or what other commands can I use that will point me to where Java is installed?
Try:
which java
This should give you the path of the java binary. It might be a link to another file, which you'll be able to check with:
ls -l `which java`
In your case Java doesn't seem to have been removed completely.
Go to /Library/PreferencePanes/JavaControlPanel.prefPane and remove it from command line. You might need sudo access.
Also remove the JavaAppletPlugin from /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
Again sudo access is necessary