AWS SDK jar file not active

I am trying to use the AWS Java SDK 1.11.534 in Lucee

If I look in the Admin screen bundle jar I see that the correct version is found and shows a status of loaded.
But when I try to instantiate any of the classes:

var test = createObject( 'java', '').build();

I get this error:
cannot load class through its string name, because no definition for the class with the specified name [com.amazonaws.auth.BasicAWSCredentials] could be found caused by (java.lang.ClassNotFoundException:com.amazonaws.auth.BasicAWSCredentials not found by lucee.core.

The other jars I added into the same lib show as active.
What am I missing here?

hard to say for sure…but it is saying it can’t find the class ‘BasicAWSCredentials’

In my case I was accessing the aws Parameter Store and I ended up recompiling the aws jar (aws-java-sdk 1.11.500) using maven because certain jars I needed were not included and then it worked.

I will look at that, but If I open the jar file, I can navigate to that class with the correct path so it looks like it is actually in the Jar correctly.

I think in my case (should have documented it better!) the jar was there but it was the wrong version.
I’m sure it’s not a Lucee problem more that the aws-java-sdk is constantly changing/being updated.
Its a painful process when you’re not used to java (which I’m not) but eventually by watching the error messages and investigating the java classes you should be able to figure it out.

In the long run it’s worth the effort because being able to leverage java classes in Lucee is sweet!

I haven’t used AWSLambdaClientBuilder, but here’s how I got to the AWSCredentials part:
(jarLocation is where the newly compiled (maven) jar resides)

<cfset var SystemPropertiesCredentialsProvider = CreateObject(‘java’,‘com.amazonaws.auth.profile.ProfileCredentialsProvider’, jarLocation)>

<cfset var AWSCredentialsProvider = CreateObject(‘java’,‘com.amazonaws.auth.AWSCredentialsProvider’, jarLocation)>

<cfset var InstanceProfileCredentialsProvider = CreateObject(‘java’,‘com.amazonaws.auth.InstanceProfileCredentialsProvider’, jarLocation)>

<cfset var awsCredentials = CreateObject(‘java’,‘com.amazonaws.auth.BasicAWSCredentials’, jarLocation).init(credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey())>

1 Like

Thanks to some hints from Andrew2 I have come up with a work around but I still think there might be an issue here with Lucee or CFML, or possibly just the documentation.

createObject( 'java', 'com.amazonaws.auth.BasicAWSCredentials', '/mypath/aws-java-sdk.jar')

If I manually give the path of the library jar file in the createObject call then it finds it just fine, but this was equally confusing because the .jar files that I put into WEB-INF/lib are getting moved to WEB-INF/lucee-server/bundles so it took me a few minutes to actually find them.

I am using a commandbox image so it might be Ortus that is moving the jars to the bundle dir.

It also seems bad practice to have to include a path outside of the source code tree in the code itself.
Granted I can just move the jar files into the web app directory to avoid this but all the same a config setting makes more sense.

On the page that describes using java in Lucee here:

I copied the files from the bundles dir to the WEB-INF/lib then restarted Lucee.

Step 2 says to place the files in WEB_INF/lib to make them visible to Lucee but even if the files exist there I still need to manually include the path to avoid the class not found error.

Is there a class path setting that needs to be setup for either the lib or bundle dirs to make this work as per the docs, if there is it needs to be added to the docs on this page.

If not Lucee is clearly not operating as per the instructions provided.

Any news on getting this to work?

In my case it is working, I would strongly recommend not adding the jar files to WEB-INF/lib but instead use the bundles directory provided by Lucee. Educate yourself on how to use the bundles directory and why it’s there.
There’s a good blog post here:Using OSGI To Load A Conflicting Jar Into Lucee Server
If you add jar files to WEB-INF/lib there’s a chance that you are going to load a different version of an existing class… using the bundles directory keeps it all separate.

1 Like

Agreed. These days I think adding external jars to the /lib path should be a last resort. Building on Brad’s post, I wrote this small tool to make loading external jar bundles easier.