hapi-fhir-base/hapi-fhir-structures-dstu3 - java.lang.IllegalStateException: Could not find any HAPI-FHIR structure JARs on the classpath #495

Closed
vijayt27 opened this Issue Nov 14, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@vijayt27

James,

We are trying to upgrade our libraries from hapi-fhir dstu2 to dstu3. We were able to upgrade and resolve all the conflicts but getting issue while initiating FHIRContext with below error.

java.lang.IllegalStateException: Could not find any HAPI-FHIR structure JARs on the classpath. Note that as of HAPI-FHIR v0.8, a separate FHIR strcture JAR must be added to your classpath (or project pom.xml if you are using Maven)
	at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:190) ~[hapi-fhir-base-2.0.jar!/:na]
	at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:163) ~[hapi-fhir-base-2.0.jar!/:na]
	at ca.uhn.fhir.context.FhirContext.<init>(FhirContext.java:136) ~[hapi-fhir-base-2.0.jar!/:na]
	at ca.uhn.fhir.rest.server.RestfulServer.getFhirContext(RestfulServer.java:401) ~[hapi-fhir-base-2.0.jar!/:na]
	at ca.uhn.fhir.rest.server.RestfulServer.init(RestfulServer.java:751) ~[hapi-fhir-base-2.0.jar!/:na]

Upgraded the maven dependencies to dstu3 version 2.0 as below and initiated FhirContext with
FhirContext.forDstu3()

<dependency>
	<groupId>ca.uhn.hapi.fhir</groupId>
	<artifactId>hapi-fhir-base</artifactId>
	<version>2.0</version>
</dependency>
<dependency>
	<groupId>ca.uhn.hapi.fhir</groupId>
	<artifactId>hapi-fhir-structures-dstu3</artifactId>
	<version>2.0</version>
</dependency>

When we verified, the FhirContext initialization in hapi-fhir-base 2.0, does not look for version Dstu3 which happend to cause this exception,

https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java

private FhirContext(FhirVersionEnum theVersion, Collection<Class<? extends IBaseResource>> theResourceTypes) {
		VersionUtil.getVersion();

		if (theVersion != null) {
			if (!theVersion.isPresentOnClasspath()) {
				throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructuresForSpecifiedVersion", theVersion.name()));
			}
			myVersion = theVersion.getVersionImplementation();
		} else if (FhirVersionEnum.DSTU1.isPresentOnClasspath()) {
			myVersion = FhirVersionEnum.DSTU1.getVersionImplementation();
		} else if (FhirVersionEnum.DSTU2.isPresentOnClasspath()) {
			myVersion = FhirVersionEnum.DSTU2.getVersionImplementation();
		} else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) {
			myVersion = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation();
		} else {
			throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructures"));
		}

		if (theVersion == null) {
			ourLog.info("Creating new FhirContext with auto-detected version [{}]. It is recommended to explicitly select a version for future compatibility by invoking FhirContext.forDstuX()", myVersion.getVersion().name());
		} else {
			ourLog.info("Creating new FHIR context for FHIR version [{}]", myVersion.getVersion().name());
		}
		
		myResourceTypesToScan = theResourceTypes;
	}

Could you please verifiy if this is a miss or do we need to add/update any other dependencies?

Thanks,
Vijay

@jamesagnew

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Nov 14, 2016

Owner

This does look like a version is missing there, I'd agree.

You can work around this by passing in a copy of a context for the appropriate version to the RestfulServer's constructor (or by calling setContext in the initialization method), which is better anyhow since it avoids the server guessing which version you want.

Owner

jamesagnew commented Nov 14, 2016

This does look like a version is missing there, I'd agree.

You can work around this by passing in a copy of a context for the appropriate version to the RestfulServer's constructor (or by calling setContext in the initialization method), which is better anyhow since it avoids the server guessing which version you want.

@vijayt27

This comment has been minimized.

Show comment
Hide comment
@vijayt27

vijayt27 Nov 14, 2016

Do we have any sample for the workaround?

We are facing while FhirContext initialization itself, so even when passing FhirContext with DSTU3 version in constructor will have this problem.

new FhirContext(FhirVersionEnum.DSTU3)

Do we have any sample for the workaround?

We are facing while FhirContext initialization itself, so even when passing FhirContext with DSTU3 version in constructor will have this problem.

new FhirContext(FhirVersionEnum.DSTU3)

@jamesagnew

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Nov 15, 2016

Owner

Try initializing the context using the static initializer, ie.

FhirContext ctx = FhirContext.forDstu3();
Owner

jamesagnew commented Nov 15, 2016

Try initializing the context using the static initializer, ie.

FhirContext ctx = FhirContext.forDstu3();
@vijayt27

This comment has been minimized.

Show comment
Hide comment
@vijayt27

vijayt27 Nov 15, 2016

James,

No luck still.

FhirContext.forDstu3() was my initial try, and I also tried all the otherways.

public static FhirContext forDstu3() {
    return new FhirContext(FhirVersionEnum.DSTU3);
}

All the constructor methods will eventually hit FhirContext(FhirVersionEnum.DSTU3)contructor
and there is no way to assign "IFhirVersion"(FhirDstu3) to FhirContext with out version number ("FhirVersionEnum")

so not sure if there is a workaround in creating fhircontext with dstu3 structure?
Sorry If miss something,
Thanks,
Vijay

James,

No luck still.

FhirContext.forDstu3() was my initial try, and I also tried all the otherways.

public static FhirContext forDstu3() {
    return new FhirContext(FhirVersionEnum.DSTU3);
}

All the constructor methods will eventually hit FhirContext(FhirVersionEnum.DSTU3)contructor
and there is no way to assign "IFhirVersion"(FhirDstu3) to FhirContext with out version number ("FhirVersionEnum")

so not sure if there is a workaround in creating fhircontext with dstu3 structure?
Sorry If miss something,
Thanks,
Vijay

@jamesagnew

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Nov 15, 2016

Owner

Ok, something is definitely up with your environment in that case. It's definitely possible to create STU3 servers using the static constructor method, we've done this lots of times. :)

I'm wondering if you have a stray old version of HAPI still being bundled in your WAR file or something like that? Can you try running a full mvn clean install and then verifying that there is only one hapi-fhir-base JAR in the WAR?

Owner

jamesagnew commented Nov 15, 2016

Ok, something is definitely up with your environment in that case. It's definitely possible to create STU3 servers using the static constructor method, we've done this lots of times. :)

I'm wondering if you have a stray old version of HAPI still being bundled in your WAR file or something like that? Can you try running a full mvn clean install and then verifying that there is only one hapi-fhir-base JAR in the WAR?

@vijayt27

This comment has been minimized.

Show comment
Hide comment
@vijayt27

vijayt27 Nov 15, 2016

your are right, its my bad.

FhirContext.forDstu3(); is indeed working, my code internally tried to initialize again with out version which caused the issue.

your are right, its my bad.

FhirContext.forDstu3(); is indeed working, my code internally tried to initialize again with out version which caused the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment