0

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?

719016
  • 9,922
  • 20
  • 85
  • 158
  • StringConcatFactory is since Java 9. Maybe check the java version (java -version). – Christian Fries Aug 19 '19 at 10:33
  • 1
    what is the java -version? – TruckDriver Aug 19 '19 at 10:34
  • Ah! I see. I think I had a borked installation of openjdk-9 for `jdb` and an older java for `java`. I have now corrected following: https://askubuntu.com/questions/176121/dpkg-error-trying-to-overwrite-file-which-is-also-in – 719016 Aug 19 '19 at 10:36

1 Answers1

0

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.

719016
  • 9,922
  • 20
  • 85
  • 158