Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError at java command to run demo project #10

Closed
answerquest opened this issue Aug 11, 2018 · 5 comments
Closed

NoClassDefFoundError at java command to run demo project #10

answerquest opened this issue Aug 11, 2018 · 5 comments

Comments

@answerquest
Copy link

Hello, I'm on a Lubuntu 18.04 32-bit OS, have installed the default java runtime environment (sudo apt-get install default-jre default-jdk). Here's the version:

$ java --version
openjdk 10.0.1 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10-Ubuntu-3ubuntu1)
OpenJDK Server VM (build 10.0.1+10-Ubuntu-3ubuntu1, mixed mode)

Following the instructions on the wiki.

mvn package happened successfully.

[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /mnt/7ACA0CC0CA0C7B21/temp/onebusaway-gtfs-realtime-visualizer/target/onebusaway-gtfs-realtime-visualizer-0.0.1-SNAPSHOT.jar with /mnt/7ACA0CC0CA0C7B21/temp/onebusaway-gtfs-realtime-visualizer/target/onebusaway-gtfs-realtime-visualizer-0.0.1-SNAPSHOT-withAllDependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:00 min
[INFO] Finished at: 2018-08-11T10:45:15+05:30
[INFO] Final Memory: 15M/30M
[INFO] ------------------------------------------------------------------------

...but with the next java command, ran into error:

$ java -jar target/onebusaway-gtfs-realtime-visualizer-0.0.1-SNAPSHOT.jar \
>   --vehiclePositionsUrl=http://developer.mbta.com/lib/gtrtfs/Vehicles.pb
Exception in thread "main" com.google.inject.internal.util.$ComputationException: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct
	at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
	at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
	at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
	at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
	at com.google.inject.internal.MembersInjectorStore.get(MembersInjectorStore.java:65)
	at com.google.inject.internal.Initializer$InjectableReference.validate(Initializer.java:120)
	at com.google.inject.internal.Initializer.validateOustandingInjections(Initializer.java:75)
	at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:139)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
	at com.google.inject.Guice.createInjector(Guice.java:95)
	at com.google.inject.Guice.createInjector(Guice.java:72)
	at org.onebusaway.gtfs_realtime.visualizer.VisualizerMain.run(VisualizerMain.java:57)
	at org.onebusaway.gtfs_realtime.visualizer.VisualizerMain.main(VisualizerMain.java:39)
Caused by: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct
	at org.onebusaway.guice.jsr250.JSR250Module$1.hear(JSR250Module.java:68)
	at com.google.inject.internal.MembersInjectorStore.createWithListeners(MembersInjectorStore.java:102)
	at com.google.inject.internal.MembersInjectorStore.access$000(MembersInjectorStore.java:34)
	at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:42)
	at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:39)
	at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39)
	at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
	... 12 more
Caused by: java.lang.ClassNotFoundException: javax.annotation.PostConstruct
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
	... 19 more

In python there's usually a module missing. I'm not so familiar with what to do in java though.

Searching the net gives this same error is happening in many other projects. Most are talking about Eclipse, Java 9, and they talk about adding something in eclipses' .ini. But I have java 10, no eclipse, so what do I do?

Ref: stackoverflow | bugs.eclipse | issues.apache | interviewbubble

@barbeau
Copy link
Member

barbeau commented Aug 11, 2018

@answerquest This is likely related to Java 9 (and 10)'s new module concept. In Java 8 and below many modules were loaded by default when running the JVM. Java 9 changed this, so for Java 9 and higher you need to include an extra command-line parameter to tell the JVM load certain modules that were previously included by default.

Try something like:

java --add-modules java.annotations.common -jar target/onebusaway-gtfs-realtime-visualizer-0.0.1-SNAPSHOT.jar \
>   --vehiclePositionsUrl=http://developer.mbta.com/lib/gtrtfs/Vehicles.pb

The main question is what to include after the --add-modules parameter.

@answerquest
Copy link
Author

Thanks @barbeau . Couple of changes more needed on the command:

  1. the module is now named as java.xml.ws.annotation, see reference
  2. The path to the MBTA feed has changed. New one: https://cdn.mbta.com/realtime/VehiclePositions.pb

New command:

java --add-modules java.xml.ws.annotation -jar target/onebusaway-gtfs-realtime-visualizer-0.0.1-SNAPSHOT.jar --vehiclePositionsUrl=https://cdn.mbta.com/realtime/VehiclePositions.pb

It got started, works but with a few issues / warnings:

  1. I'll have to put in my Google Maps API key somewhere. (pls suggest where). Screenshot of page: click here
    Link that google takes us to.

  2. Terminal shows this warning on starting, doen't seem to be blocking anything but sharing it here for the record.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/mnt/72B627F7B627BB0D/TECH/python-scratch/MBTA-realtime/onebusaway-gtfs-realtime-visualizer/target/onebusaway-gtfs-realtime-visualizer-0.0.1-SNAPSHOT.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

This is running now so I'll close this issue and open a new one to track the google maps api thing.

@answerquest
Copy link
Author

made an edit on the wiki page to show changed path to MBTA feed, and added extra command to run in case of error.
Hope that's ok?

@barbeau
Copy link
Member

barbeau commented Aug 12, 2018

Thanks @answerquest! Yes, updating the wiki is great.

@answerquest
Copy link
Author

Note: the modules seem to have been entirely removed from java from v11 onwards. See : https://jaxenter.com/jdk-11-java-ee-modules-140674.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants