NoClassDefFoundError: ca/uhn/fhir/context/FhirContext

727 views
Skip to first unread message

Carty Castaldi

unread,
Jan 5, 2022, 11:45:00 AM1/5/22
to HAPI FHIR
Team,

I am making progress with the skeleton client,  I commit here to help future java/maven newbies, there is so much cool stuff here.

I am running on a Debian machine at GCP, no IDE just java and maven.
$ java --version
openjdk 11.0.13 2021-10-19
$ mvn -v
Apache Maven 3.6.0

Maven build runs OK, I execute the TestApplication class:

$ java -cp target/hapi-fhirstarters-client-skeleton-5.0.0.jar test.TestApplication

and at the first call out:
 
FhirContext ctx = FhirContext.forR4();

I get the exception:

Exception in thread "main" java.lang.NoClassDefFoundError: ca/uhn/fhir/context/FhirContext at test.TestApplication.main(TestApplication.java:19)Caused by: java.lang.ClassNotFoundException: ca.uhn.fhir.context.FhirContext 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:522) ... 1 more

I have learned a ton about maven and java configs in the last days but am stuck, I very much appreciate any help.

-Carty


Carty Castaldi

unread,
Jan 5, 2022, 12:07:28 PM1/5/22
to HAPI FHIR
More info I did a maven dependency check:

[WARNING] Used undeclared dependencies found:[WARNING] ca.uhn.hapi.fhir:org.hl7.fhir.r4:jar:5.5.7:compile[WARNING] Unused declared dependencies found:[WARNING] ca.uhn.hapi.fhir:hapi-fhir-client:jar:5.6.0:compile[WARNING] ca.uhn.hapi.fhir:hapi-fhir-structures-r4:jar:5.6.0:compile[WARNING] ch.qos.logback:logback-classic:jar:1.2.3:compile

--
You received this message because you are subscribed to a topic in the Google Groups "HAPI FHIR" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hapi-fhir/-1Zd983ogsM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/7cc7a7f0-b1af-4aae-903a-d1290dd43b30n%40googlegroups.com.

Carty Castaldi

unread,
Jan 11, 2022, 11:03:14 AM1/11/22
to HAPI FHIR
Update in case anyone has a similar problem, I installed Eclipse on my mac and there the client skeleton builds and executes fine.

The issue will continue to bug me but I can now compare the two configs, I'd like to be able to run on a headless unix VM, will post here as I learn more.

Carty Castaldi

unread,
Jan 12, 2022, 11:29:05 AM1/12/22
to HAPI FHIR
OK I installed Eclipse on my (headless) Debian VM with remote desktop and the Client Skeleton compiles and runs fine, my issue is apparently related to running outside Eclipse.

AfternoonLemon

unread,
Oct 1, 2024, 12:16:20 PM10/1/24
to HAPI FHIR
Just in case anyone else encountered this problem, and were using Maven to compile: it does not include dependencies in the output jar file by default.

Adding this plugin to pom.xml solved it for me:

<plugin>
<!-- NOTE: We don't need a groupId specification because the group is
org.apache.maven.plugins ...which is assumed by default.
-->
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Reply all
Reply to author
Forward
0 new messages