AWS SDK jar file not active

#1

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

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', 'com.amazonaws.services.lambda.AWSLambdaClientBuilder').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?

#2

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.
see:https://stackoverflow.com/questions/1729054/including-dependencies-in-a-jar-with-maven

#3

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.

#4

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())>

#5

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:
https://docs.lucee.org/guides/Various/tutorial-lucee/tutorial-java-in-lucee.html.

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.