Open Micah-Gafford opened 6 months ago
what does your classpath look like when you try to run the jar? The gradle build doesn't bundle all the dependencies into the jar that is built, so you'll need to make sure they are on your classpath.
how are you running the jar?
I was able to move beyond the initial java.lang.NoClassDefFoundError
by add the following to my build.gradle.kts
file:
from(configurations.compileClasspath.get().map { if (it.isDirectory()) it else zipTree(it) })
I am now running into a similar issue during runtime when trying to build the OtlpGrpcSpanExporter
. See here:
Exception in thread "main" java.lang.NoClassDefFoundError: io/opentelemetry/exporter/internal/marshal/Marshaler
at com.example.exporter.ExampleConfiguration.initOpenTelemetry(ExampleConfiguration.java:43)
at com.example.exporter.OtlpExporterExample.main(OtlpExporterExample.java:25)
Caused by: java.lang.ClassNotFoundException: io.opentelemetry.exporter.internal.marshal.Marshaler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)
... 2 more
Is this just now an issue with not having added the right implementation dependencies in my Gradle build? I am running the jar using java -jar app/build/libs/app.java
.
When printing out my classpath, I get this: Classpath: app/build/libs/app.jar
You will need to include all of the dependencies, including any transitive dependencies in your classpath, otherwise, the classes that are needed will not be found.
I am also running into a similar issue. Based on the information here, I've tried two things:
1) I've downloaded the io.opentelemetry jars listed in the build.gradle.kts and added them to my classpath 2) I've tried using the maven repository dependancies tab and to keep adding those dependancies in build.gradle.kts. I was able to get past one ClassNotFoundException just to hit another one. Here are some of the libraries I've added:
Can someone share a list of dependencies to add to build.gradle.kts or classpath?
Does ./gradlew run
work?
Check out this pull request where I add the application plugin. https://github.com/open-telemetry/opentelemetry-java-examples/pull/361 With that PR in place, all you have to do is...
cd otlp
../gradlew run
(after starting up the docker-compose setup in the docker directory)
@jkwatson Thank you!
I did get the project to run. However, first I had to remove
":opentelemetry-examples-spring-native",
from settings.gradle.tks as that caused a build failure.
If you address that or mention something in the readme, I think this issue is resolved. Thank you again!
I did get the project to run. However, first I had to remove
":opentelemetry-examples-spring-native",
from settings.gradle.tks as that caused a build failure.
Not sure what you're referring to there. Can you point me to the location on github?
I did get the project to run. However, first I had to remove
":opentelemetry-examples-spring-native",
from settings.gradle.tks as that caused a build failure.Not sure what you're referring to there. Can you point me to the location on github?
oh, in the root of the project? No idea why that would cause any failure for you. It worked fine for me as-is. Let's not confound the two issues. If you have another issue, open that as a separate one.
I think that this line val moduleName by extra { "io.opentelemetry.examples.otlp" }
referenced the include in settings.gradle.kts in the root of the project. The screenshot below is the error I got. Once I deleted the reference to spring-native, I re-ran ../gradlew run
and it worked without issue.
Please create a separate issue for that, as it doesn't have anything to do with the running of the otlp example in particular.
I am trying to follow the otlp Java example here. When attempting to run the jar produced by the gradle build I am encountering the following error:
I have tried to run with the dependencies listed in the example
gradle.build.kts
file along with a few other dependencies to try to fix the error but have had no luck. Does anyone know if there are dependencies or build requirements that aren't listed in the example that I should add in mygradle.build.kts
file?Here is my
gradle.build.kts
for reference: