I am trying to setup ANTLR4 and I am having issues setting the classpath.
I followed the instructions in the book "The Definitive ANTLR 4 Reference 2nd Edition", in section "Installing ANTLR", also I followed the instructions here and I have not got any results running in command line antlr4 or grun (the alias created).
I am running on a MacbookPro M1, Monterrey. I tried this with java 11 and 8 and the results were the same. I use sdkman to handle multiple java versions. Also my default terminal is oh-my-zsh.
In my bash_profile I added ANTLR configurations like this:
and in file zshrc I am loading configuration from bash_profile.
This is the output from my terminal.
Mac OS is gradually locking things down tighter and tighter on the system volume. While I think there's a good argument that /usr/local/ shouldn't be a part of that, it looks like it is.
Try placing your antler jar file some place within you home directory (perhaps changing all references to /usr/local to just be ~ (or maybe ~/local if you'd prefer to separate them out.)
I just downloaded the latest:
cd ~/lib
sudo curl -O https://www.antlr.org/download/antlr-4.11.1-complete.jar
changed by .zshrc to reference the new version:
export CLASSPATH=".:$HOME/lib/antlr-4.11.1-complete.jar:$CLASSPATH"
alias antlr4='java -jar $HOME/lib/antlr-4.11.1-complete.jar'
alias grun='java org.antlr.v4.gui.TestRig'
grun is running just fine
Related
I'm super new to CS and very unfamiliar with UNIX/Bash vocab.
I'm currently trying to install Maven, and I made a few mistakes by copy pasting old installation instructions (with incorrect version numbers) and now the whole process is so messed up. I first tried to follow the given instructions on the website, that didn't work, then I tried a few other ones, and now I'm worried that I'm left with a mess by following different sets of instructions.
I've reached a point now where if I type in mvn -version I get the following:
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Originally, my JAVA_HOME was set to jdk-install-dir, which still gave me the above error message. I tried redownloading the jdk (version 13.0.1) from Oracle, dragged that file to my home directory, and unzipped it. Then I set my JAVA_HOME to that unzipped file, jdk-13.0.1.jdk, and updated my PATH variable. After all this, I'm still getting this same error message, and I'm not sure what to do.
For the reference, here are what some relevant environment variables are set to (I didn't include irrelevant info from PATH):
~ echo $JAVA_HOME
jdk-13.0.1.jdk
~ echo $PATH
/usr/local/apache-maven/apache-maven-3.6.3/bin:/opt/apache-maven-3.6.3/bin:jdk-install-dir/bin:/usr/local/apache-maven/apache-maven-3.3.9/bin:/opt/apache-maven-3.6.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/allyson/apache-maven-3.6.3/bin:/Users/allyson/apache-maven-3.6.3/bin:jdk-12.0.1.jdk/bin:/Users/allyson/apache-maven-3.6.3/bin:JDK-13.0.1.jdk/bin
~ echo $M2
/usr/local/apache-maven/apache-maven-3.6.3/bin
~ echo $M2_HOME
/Users/allyson/apache-maven-3.6.3
One thing I'm curious about: for the M2 and M2_HOME variables, is it supposed to be that one is in my home directory (/Users/allyson) and one is for /usr/local?
OK, take a deep breath, and we'll walk through this. Each of these environment variables has a purpose, and once you understand what those purposes are, this makes a lot more sense. Mixing tutorials is not necessarily a problem, but you'll want to understand what you're doing, rather than just blindly copy values from the internet.
JAVA_HOME is intended to identify to the system environment where to find a java runtime environment. It needs to be set to the full path of where your JDK has been installed. On windows, this might be C:\Program Files\Java\jdk-13.0.1. On a Linux system, you have a bit more flexibility. Common locations might be /opt/java/jdk-13.0.1 or /usr/local/java/jdk-13.0.1. If you installed your JDK somewhere else, then you need to use that path instead. The message NB: JAVA_HOME should point to a JDK not a JRE refers to a common mistake when installing maven -- maven requires a JDK, not a plain JRE. This error is so common that any time JAVA_HOME points to a folder that isn't a JDK, it prints this warning (even if the folder in question isn't actually a JRE).
M2_HOME is supposed to be set to the full path where maven is installed (i.e. the place where you unzipped it). This more or less helps maven "find itself" if it should need to for whatever reason. Strictly speaking, this one isn't necessary. (It's not set on my system, and maven works fine for me). It's mostly a convenience for setting the next environment variable.
M2 is the full path to the folder where the maven executable is. This will almost always be $M2_HOME/bin, but it's certainly possible to do weird things, and this will let you work around those situations. Obviously, this won't work if you didn't specify $M2_HOME. This one isn't strictly necessary, either, and is mostly a convenient way of setting up the next one.
PATH is where your Linux system looks to find programs to run when you type their name on the command line. For ease of use, you'll want to make sure that the maven and java executables are included somewhere in the : delimited list. Most Linux distributions already have a default PATH set up for you in a shell resource file of some kind. You'll want to refer to their documentation for how to add another entry to the path, but a common idiom would be PATH=$PATH:$M2 (which would append the value of $M2 to the value of $PATH and then store the result back into PATH. If you didn't set up $M2 or $M2_HOME, you'll need to do something else.
So, TL;DR, if you installed your JDK in /opt/java/jdk-13.0.1 and unzipped maven into /opt/maven/apache-maven-3.6.3, your bear minimum working values are:
export JAVA_HOME=/opt/java/jdk-13.0.1
export PATH=$PATH:$JAVA_HOME/bin:/opt/maven/apache-maven-3.6.3/bin
And if you wanted a complete set
export JAVA_HOME=/opt/java/jdk-13.0.1
export M2_HOME=/opt/maven/apache-maven-3.6.3
export M2=$M2_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin:$M2
It's worth noting that most Java IDEs will include a GUI for setting up maven and Java within the IDE (the settings will typically only work within that IDE). It's often much easier for beginners to get up and running that way.
$JAVA_HOME should be a full path, not the dir name.
scream#kafka1:~$ echo $JAVA_HOME
/opt/java/jdk-11.0.5/
scream#kafka1:~$
I'm working on Ubuntu 20, and my own issue was about the jdk version located in the JAVA_HOME variable, which wasn't the right version. This was my trip around that issue:
First, What is the JAVA_HOME value?
$ echo $JAVA_HOME
$ /usr/lib/jvm/jdk-11.0.10
Next question/step, where is the Java app pointing to?
(Source: https://stackoverflow.com/a/42706056/2373421)
$ java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'
java.home = /usr/lib/jvm/jdk-11.0.12
So, the JAVA_HOME variable wasn't keeping the right value. Let's change that:
$ export JAVA_HOME=/usr/lib/jvm/jdk-11.0.12
The test outcome is right now:
$ mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /opt/apache-maven-3.8.1
Java version: 11.0.12, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-11.0.12
I'm doing this for future me's bc after all the links in StackOverflow, the solution was to check mvn.cmd file on C:\Program Files\Maven\apache-maven-3.6.3\bin...
On line 52 it sets the JDK, but it didn't had the "/bin" where my OpenJDK 15 stored the java.exe
This fixed the issue on Windows 11 but it could serve as an idea for other OS. Hope that it helps!
OS: Windows 7, 64-bit
Here I learn that the latest version of Jython (downloads/installs as "2.7.0") includes the "ensurepip" module, which hopefully installs pip.
This is what I get... NB there is no drive "Z:" on my machine
D:\apps\jython2.7.0\bin>jython -m ensurepip
Traceback (most recent call last):
File "<string>", line 444, in <module>
File "<string>", line 435, in main
File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess",
line 522, in call
File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess",
line 710, in __init__
File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess",
line 958, in _execute_child
WindowsError: [Error 2] The system cannot find the file specified
In fact I get the above error if I simply enter "jython" [Return]!
In the readme.txt file I see this:
This is the final release of the 2.7.0 version of Jython. Along with
language and runtime compatibility with CPython 2.7.0, Jython 2.7
provides substantial support of the Python ecosystem. This includes
built-in support of pip/setuptools (you can use with bin/pip) and a
native launcher for Windows (bin/jython.exe), with the implication
that you can finally install Jython scripts on Windows.
I have no idea what they mean by "you can use with bin/pip"... the bin directory (\bin on Windoze) contains 2 files: jython.exe and python27.dll.
Furthermore I don't know how to get the interactive terminal for Jython running with this
15 mins later
2 up votes! I wasn't expecting that. I thought it was likely something anomalous I had done on my machine was to blame. Now I'm beginning to wonder whether the Jython team (who are geniuses by the way) are just so uninterested in Windoze boxes that they just packaged this up and flung it out there without testing it on any Windoze boxes at all!
a few days later
Followed Jim Baker's advice: perfectly smooth installation. "pip install" working fine!
JAVA_HOME must be set such that %JAVA_HOME%\bin\java.exe is the Java executable, and the target java.exe must be Java 7. See this Jython bug. It is important to note that some other possible settings for that environment variable do not work - we expect that bin\java.exe can be joined to JAVA_HOME (using os.path.join to be precise). Also it is important to set JAVA_HOME exactly per what Windows expects in terms of quoting, etc:
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_55
but not
set JAVA_HOME="C:\Program Files\Java\jdk1.7.0_55"
(Not at all the same! Just try it to see what I mean.)
The easiest way to debug these problems is with jython --print; for example on my system I get the following:
C:\jython2.7.0>set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_55
C:\jython2.7.0>bin\jython.exe --print
"C:\Program Files\Java\jdk1.7.0_55\bin\java" -Xmx512m -Xss1024k -classpath C:\jython2.7.0\jython.jar;. -Dpython.home=C:\jython2.7.0 -Dpython.executable=C:\jython2.7.0\bin\jython.exe -Dpython.launcher.uname=windows -Dpython.launcher.tty=true org.python.util.jython
Let me next explain the opaque error you are seeing. There are two things going on:
jython.exe is actually the Jython launcher; the real Jython we use is seen in the output of jython --print; it is org.python.util.jython, plus a bunch of other options. But we need an exe so that pip and other tooling can work. On Windows (or on other OSes if profiling for example is turned on), the launcher uses subprocess to invoke the Java executable. This subprocess invocation is in line 435 of jython.py.
Yes, that's jython.py. It actually uses CPython 2.7 (thanks for being around CPython, we like you!), and is wrapped into an executable by PyInstaller. The whole thing about "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess",
is due to the fact that I built jython.exe on my Z: drive, onto which my install of Windows 8.1 on VMWare has mapped my OS X homedir. (Yes, I'm completely responsible for this build.) Next, out00-PYZ.pyz refers to some internal scheme used by PyInstaller.
We need to complete the release notes wiki update I mention on that bug! And of course fix that bug so it provides a better error message and possibly can recover in certain cases.
I also installed the Jython and was facing the same error after setting the JAVA_HOME to C:\Program Files\Java\jdk-10.0.2 works for me.
set JAVA_HOME=C:\Program Files\Java\jre1.8.0_281
jython
I have problems after uninstalling jdk 7 on mac book pro with rm -rf /Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdk
I also have installed java 8 and Intellij works well. But any attempt to run java -version or mvn crashes with error:
dyld: could not load inserted library '/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre/lib/libjsig.dylib' because image not found
[1] 1216 trace trap mvn
And in the same time I can build all the projects with IntelliJ.
I even can't run vim - I have the same mistake.
So, my questions:
1. What is the correct way to uninstall JDK?
2. What should I do in my situation to restore the system?
As mentioned by mattias in his answer, your problem stems from a command in one of your bash startup files, that tells bash to load certain dynamic libraries before it attempts to run any command.
Using unset DYLD_INSERT_LIBRARIES will only solve this temporarily, for the current running terminal. So you should fix the problem permanently, by first running that command, and then editing your .bash_profile and .bashrc files with vim or nano.
If you see a line that says
export DYLD_INSERT_LIBRARIES=/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre/lib/libjsig.dylib
just remove this line. If it inserts any additional libraries in addition to that libraries, just erase this particular library from /Library to libsig.dylib including the following : (if it's the last one, then the preceding :).
Exit Terminal, run it again and make sure your problem has been solved.
The procedure you have been following for removing the JDK is the correct one as suggested by Oracle. The problem was that once in the history of that machine, you or whoever was using it added that library to the DYLD_INSERT_LIBRARIES environment variable and this caused the problem. Also, the reason why this did not affect IntelliJ is that it is not running through bash, so bash commands do not affect it.
If you want to remove any other Java version, you should do the same as you did before, but make sure in advance that nothing in DYLD_INSERT_LIBRARIES refers to something inside /Library/Java/JavaVirtualMachines.
Have a look in your .bash_profile and try to look for
export DYLD_INSERT_LIBRARIES=/usr/lib/libSaturnFE.dylib
export DYLD_FORCE_FLAT_NAMESPACE=1
or anything similar. These might be causing the problem you experience.
Try commenting them out and reload your bash with
exec bash
and see if the problem persist.
I need to uninstall Java jdk1.6.0.27 from RHEL 5.7 and then install another version jre-7u40-linux-x64.rpm.
The firs thing I did was to find out the current java version installed using the
java -version command and the output is "java version "1.6.0_27"".
After that I tried to check the previews version of java with the command:
rpm -qi jdk
The output is "package jdk is not installed"
After installing the package jre-7u40-linux-x64.rpm in the /usr/java directory there are two java packages.
The output of the ls command on /usr/java is:
default jdk1.6.0_27 jre1.7.0_40 jre-7u40-linux-x64.rpm latest.
when I run the command "alternatives --config java" the output is:
*+ 1 /usr/java/latest/bin/java
I am new to RHEL and I need some help to understand the situation.
To conclude I need some help to remove the previews jdk1.6.0.27 and to install jre1.7.0_40.
Thank you in advance for your help!
Best regards,
Claudio
First, find out your real java executable. Start with
which java
This is going to give you some response such as:
/usr/bin/java
Next, do
ls -l /usr/bin/java
(Or whatever it returned).
It will probably write something like:
/usr/bin/java -> /etc/alternatives/java
Do the same for whatever is pointed to by the arrow, until finally, when you do ls -l on it, there is no arrow.
Then, for that particular file, find out which rpm provides it by using
rpm -q -f <full path of the file you found>
It should tell you which package it belongs to, and then you can uninstall that.
However, if the rpm command returns The file ... is not owned by..., then your Java has not been installed using an rpm. It may have been installed manually by someone in the past.
This makes uninstalling it a lot more problematic.
If you haven't found your answer:
leave old java where it is, don't even bother with it
install new version with: rpm -ivh /root/jdk-7u40-linux-x64.rpm
deactivate old java
export new version
Deactivating old java (note entering hashtags before every line, manual installation required editing of profile, so edit it one more):
vi /etc/profile
#JAVA_HOME=/usr/java/jdk1.6.0_27
#export JAVA_HOME
#PATH=$JAVA_HOME/bin:$PATH
#export PATH
Exporting nev version (note adding new lines in profile followed after old entries):
export JAVA_HOME=/usr/java/latest
export JRE_HOME=$JAVA_HOME/jre
export J2RE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$J2RE_HOME/bin:$PATH
Check nev version with standard command for checking of installed sw.
Hope this suits your needs.
Just wondering: you're trying to prepare BFBOX for acceptance? Just courious! If you want more info please send me an email, ok?
I have installed Java 1.7.0_45 on Mac OS X 10.6.8 using Pacifist [http://www.charlessoft.com/] however I am unable to run a jar file which I have downloaded. The jar file is a threaded application.
The error message I am getting is:
java -jar context.jar
2013-10-31 14:14:41.898 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement methodSignatureForSelector: -- trouble ahead
2013-10-31 14:14:41.900 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement doesNotRecognizeSelector: -- abort
Trace/BPT trap
Is there anyway I can run the jar. I have set the JAVA_HOME path properly and java -version is showing 1.7.0_45 as the version.
The same application works properly on Windows Java 1.7.0_45 and also on Linux Java 1.7.
The web search for the solution and the given keywords return very few results and none of them have any specific solution in it. I am new to mac so I am not fully able to understand the issue.
Alternatively, is there anyway I can run Java from folder in Mac like I can do in windows and Linux by just extracting the Java contents and changing the JAVA_HOME. If that is possible then I should be able to run my JAR.
I had kind of same problem while installing an application through jar file, my Java was not detected by the jar application installer,
Over here I see that one of the method is not accessible, could be a same problem. But I am not very sure of it.
make sure you have rt.jar in your JAVA_HOME/jre/lib/ folder
In case you don't have then you are required to have it through the process of creation of symbolic link.
In the command below replace your_java_version with proper version matching your requirement.
sudo mkdir -p /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib
Go into the directory:
cd /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib/
Create symbolic link :
sudo ln -s ../../../Classes/classes.jar rt.jar
Hope this solves your problem.
I get the exact same problem with MacOS 10.6.8 and JDK 7. In order to run the jar I had to use the System JRE which is 1.6.x (In my case I wanted to install Squirrel
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar >squirrel-sql-3.6-MACOSX-install.jar