I am trying to run my .jar file on a linux server.
These are the commands I'm running:
JAVA_HOME=/app/local/opt/jdk/packages/jdk1.6.0_30/
export PATH=$JAVA_HOME/bin:$PATH
cd folder
nohup java -jar program.jar &
When ran on Friday, this was working perfectly. However, today I am getting:
Unrecognised option: - Could not create the Java virtual machine.
In my nohup.out
If I run java -v after setting the path I get the same problem. Can anyone suggest anything? Really confused about this.
Thanks for any help on this.
Usually, when we get this kind of exception ("Unrecognised option" which causes the "Could not create the Java virtual machine"), the JVM displays the unrecognized option, like this:
Unrecognised option: -[option details] Could not create the Java virtual machine.
the fact that you have no details makes it seem as though you just have a space (" ") in your command.
Take a look again to make sure.
I've got this failure running maven on Win10 where the pom.xml is located in a folder named something like C:\dir\OneDrive - bar\workspace\project.
Moving the project to a different folder solved it.
First of all, there is no -v option on the java command.
(Reference: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html ... Java 6 version ... 'cos that is what you are using. Try java -help for the short list of options.)
So it is expected for java -v to fail.
As an experiment I tried this (with an OpenJDK Java 8 JDK on Fedora 22):
$ java -foop
Unrecognized option: -foop
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
$
As you can see, the "unrecognized option" message tells me what option it doesn't understand. Looking at the message in your question, we see that it is saying it is "-". That doesn't appear to match the command line in your question, but on the other hand the command line in your question does not have any invalid options.
Another possibility, I guess, is that you have a shell alias called java. That would take precedence over any commands on the shell's command path.
The other thing is that you are running an ancient version of Java. Java 6 has passed end-of-life, and the last publicly released version is update 45. You are running update 30 which was released in December 2011. There have been LOTS of security patches since then. I'd recommend upgrading to Java 8 ... and making sure that you keep it up to date.
for java 8 run 'java -version'
for java 9 or 9+ run 'java --version'
Had the same issue under Linux/Ubuntu 20.04.
I created a bash to run my jar and used some variables in the file
# This line below shows the error
$JAVA_PATH "-jar $JVM_ARGS $JAR_PATH"
# This line below runs without issue
$JAVA_PATH "-jar" $JVM_ARGS $JAR_PATH $SB_ARGS
I don't know why it works after using double quotes for the "-jar" option only, I think it's something to do with UNIX systems.
Related
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
I am using the code from this tutorial to test the JDBC connection. I changed the name of the class to TestJDBC and I altered the database name and query, but otherwise it is identical. When I run the class as a Java application from within eclipse on my devbox, the program runs properly. However, when I copy the file to /home/username/ on a remote CentOS 7 server, typing java TestJDBC.java into the terminal produces the following error:
Error: Could not find or load main class TestJDBC.java
I also the same error when I try java TestJDBC and when I upload the .class file in addition to just the .java file. What else do I need to do in order to call the Java class from the CentOS 7 terminal?
Note that javac TestJDBC.java results in -bash: javac: command not found. And I did try java somepackage.TestJDBC with same results of Error: Could not find or load main class TestJDBC.java as above.
ANSWER NOTE: The answer required getting the development version of openJDK using yum. The PATH variable was not part of the solution. However, I am marking the answer below as accepted because the user who submitted it contributed substantially to the solution.
You should be able to run it after compiling it
javac TestJDBC.java
java TestJDBC
Note that you do not need to add .class when running it from the commandline.
If this still does not work, please paste your code.
EDIT after request
So you've now stated that you're missing javac from your PATH. I'll show you how to add it:
$> export JAVA_HOME=/path/to/jdk/jdk.1.8.0_20
$> export PATH=$PATH:$JAVA_HOME/bin
Verify by running
javac -version
It should print something like
javac 1.8.0_20
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 am trying to compile and a sample Helloworld.java file.
I have my jdk installed in C:\Program Files\jdk1.7\bin.
And I have my Helloworld.java in C:\Helloworld.java
I am actually a novice in both powershell and java.
I got some examples from web regarding this but many of them advice to run it like this:
java.exe -classpath $Env:CLASSPATH C:\Helloworld.java
But when I give this in powershell I get an error called 'CLASSPATH' is not defined even after adding it in env variables.
And when I try to compile the code with the following syntax:
$javac C:\Helloworld.java I get an error "javac is not recognised as a token".
So, I am literally lost in this topic . Any step by step procedure to run java programs using powershell for dummies like me will be greatly appreciated.
Setup environment variables in your system.
set JAVA_HOME to C:\Program Files\jdk1.7
add to PATH variable the string %JAVA_HOME%\bin
open new cmd session.
navigate your java source folder.
use javac to compile your java files.
UPDATE:
also if you are experiencing difficulities upon launching an executable via PowerShell check this Microsoft TechNet article
The variables you speak of do not exist in PowerShell as you name them.
The correct variable names are
$Env:JAVA_HOME: C:\jdk1.6.0;
$Env:PATH: C:\jdk1.6.0\bin;.;
$Env:CLASSPATH: C:\jdk1.6.0\lib;.;
As they all must be defined in the ENV: PSDrive
To answer it in a much simpler way , its the path problem .
You probably not have set env variables that's it.
This is how you should set it:
JAVA_HOME: C:\jdk1.6.0;
PATH: C:\jdk1.6.0\bin;.;
CLASSPATH: C:\jdk1.6.0\lib;.;
And later if you open a cmd prompt and type java -version , if you are able to see the java installed version then you are good to go.
I have Oracle SQL Developer installed at the following location:
/opt/sqldeveloper
Every time I run it using the command ./sqldeveloper, I get the following error from the GUI:
You are attempting to run with Java 1.6.0_31. Running this product is
supported with a minimum Java version of 1.7.0_51 and less than 1.8
I updated the sqldeveloper.conf file with the following paths:
/usr/java/jdk1.8.0_05
and
/usr/java/jdk1.7.0_55
And despite all that, same error again.
I know I am a bit late with the response, but I had exactly the same issue until this morning.
What I did is changed:
~/.sqldeveloper/4.0.0/product.conf
FYI:
How I figure it out:
1. Go to OracleSQLDeveloper -> Help(menu) -> Properties
2. Find 'java.home'
(For some reason it was pointing to /usr/lib/jdk1.7.0 (ver 1.7.45), even I've changed sqldeveloper.conf)
3. Since I didn't recognized that specific version, I just ran:
sudo "find / .... -name '*.conf' -exec grep 'jdk1.7.0' ..."
goodluck
Configure Path to Java
SQL-Developer needs to know how to find your Java Developer Kit:
Note: You need to specify /usr/lib/jvm/java-6-openjdk-i386 on 32-bit OS installations.
Terminal
cd $HOME
mkdir -p .sqldeveloper
cd $HOME/.sqldeveloper
echo "/usr/lib/jvm/java-6-openjdk" > jdk