I am relatively unexperienced in java, so hopefully I will be able to provide enough information here for this to be relevant and useful for other people.
I am trying to run someone else's codebase that takes two input files, prints some information to STDOUT while running the code through them and quits.
I compiled the code with a command like the one below:
java -g -cp .:../../deps/dep1.jar:../../deps/dep2.jar:../../deps/dep3.jar nameofclass/Nameofclass.java nameofclass/File1.java nameofclass/File2.java nameofclass/File3.java
I can then execute with jdb
as shown below:
jdb -classpath ".:../../deps/dep1.jar:../../deps/dep2.jar:../../deps/dep3.jar:" nameofclass.Nameofclass file1.ext file2.ext
Then in jdb:
run nameofclass.Nameofclass file1.ext file2.ext
When I do so, in jdb I get the print out of the process that correctly runs the code, and finishes with a The application exited
:
Set uncaught java.langh.Throwable
Set deferred uncaught java.langh.Throwable
>
VM Started: /path/to/src
<print out of the code running correctly>
The application exited
So far, so good. When I try to run the same code with java
instead of jdb
, I get:
java -cp ".:../../deps/dep1.jar:../../deps/dep2.jar:../../deps/dep3.jar:" nameofclass.Nameofclass file1.ext file2.ext
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
with the trace pointing to a line of code at the very beginning of the main function, which does not seem to have any issues running with jdb
.
Any ideas how to run the code that I can run successfully with jdb
but simply with java
on the command-line here?
It turns out the StringFactory error was pointing the fact that my Java installation was borked in my Ubuntu 16.04, with jdb
running Java 9 but java
pointing to a /usr/bin/java
version much older than that. I corrected the issue with:
https://askubuntu.com/questions/176121/dpkg-error-trying-to-overwrite-file-which-is-also-in
and finally running:
sudo update-alternatives --config java
After doing that, running java
similarly to jdb
worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.