Skip to content

Provide working maven example #726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GuyJackson opened this issue Jan 27, 2022 · 12 comments
Closed

Provide working maven example #726

GuyJackson opened this issue Jan 27, 2022 · 12 comments

Comments

@GuyJackson
Copy link

I'm trying to trial Powertools in my demo project (specifically around logging).

I've copied this pom in your example repo and get a series of issues in my demo project - when I package (mvn clean package) and upload the produced jar to aws.

1. Cloudwatch error - Exception when using private final static Logger log = LogManager.getLogger(); in App class.

java.lang.ExceptionInInitializerError
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
Caused by: java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found.

Resolved by putting in private final static Logger log = LogManager.getLogger(**App.class**);

2. Cloudwatch error - Exception related to maven shade plugin:

ERROR StatusLogger Unrecognized conversion specifier [d]

Seems to relate to this stackoverflow post.

Resolved by adding this config to the shade plugin:

<configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <finalName>hello-world</finalName>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>**/Log4j2Plugins.dat</exclude>
                                <exclude>module-info.class</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>

3. Cloudwatch warning:

WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

Not entirely sure on the resolution for this but doesn't break things as it stands.

4. Cloudwatch Error related to log4j2.xml which is copied from your repo here.

ERROR Console contains an invalid element or attribute "LambdaJsonLayout"

I don't know how to progress past this.

Many Thanks,

@orozcoadrian
Copy link

I've seen some of these errors as well. Looks like that example folder in the repo has not been kept up-to-date with recent documentation changes. In the meantime you could try following the docs instead of that sample code: https://awslabs.github.io/aws-lambda-powertools-java/

In the end was able to get both a maven and a gradle lambda working by following the docs.

@GuyJackson
Copy link
Author

GuyJackson commented Jan 28, 2022

Thanks @orozcoadrian that was my original first point of call. Following the install steps then adding the example log4j2.xml into resources, resulted in me getting this error in the Cloudwatch logs:

ERROR Console contains an invalid element or attribute "JsonTemplateLayout"

Since getting the above error, I had a sniff around for examples and came here...

It's not entirely clear to me from the docs what other additional dependencies need to be included for this to work re: log4j2.

@pankajagrawal16
Copy link
Contributor

Thanks @orozcoadrian that was my original first point of call. Following the install steps then adding the example log4j2.xml into resources, resulted in me getting this error in the Cloudwatch logs:

ERROR Console contains an invalid element or attribute "JsonTemplateLayout"

Since getting the above error, I had a sniff around for examples and came here...

It's not entirely clear to me from the docs what other additional dependencies need to be included for this to work re: log4j2.

Hi @GuyJackson Which version of powertools are you using ?

@pankajagrawal16
Copy link
Contributor

I would also recommend using quick start template documented here https://awslabs.github.io/aws-lambda-powertools-java/ to get a sample maven or gradle app.

Note, Support for JsonTemplateLayout was introduced in version v1.10.0

@pankajagrawal16
Copy link
Contributor

Also as @orozcoadrian pointed, please avoid referring example folder within the project. We will soon be moving it out of the project itself.

@GuyJackson
Copy link
Author

@pankajagrawal16 thanks for the reply, I'm using 1.10.2 version of powertools. I missed the cookie cutter in the docs:

sam init --location gh:aws-samples/cookiecutter-aws-sam-powertools-java

Will see what that produces.

@pankajagrawal16
Copy link
Contributor

Cool, Let us know how it goes. :)

@GuyJackson
Copy link
Author

GuyJackson commented Jan 28, 2022

running:

sam init --location gh:aws-samples/cookiecutter-aws-sam-powertools-java

I get errors on windows and linux (on different machines).

Windows (11) errors:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\xxxxx\.cookiecutters\cookiecutter-aws-sam-powertools-java'
2022-01-28 21:05:07 Stopping generation because post_gen_project hook script didn't exit successfully
Error: An error occurred while generating this project None: Hook script failed (exit status: 1)

SAM CLI, version 1.37.0

WSL2 Linux (Ubuntu) error:

Choose from 1, 2, 3 [1]: 1
Select dependency_manager:
1 - Maven
2 - Gradle
Choose from 1, 2 [1]: 1
2022-01-28 20:50:08 Command /tmp/tmp8c24vp_u.py not available

SAM CLI, version 1.37.0

@pankajagrawal16
Copy link
Contributor

Hmm , this seems odd. I cannot seem to replicate this issue on mac atleast. Do you have any more logs to share?

@GuyJackson
Copy link
Author

GuyJackson commented Feb 1, 2022

@pankajagrawal16 My colleague who has a Mac also confirmed it to be working (like you) and shared the generated project with me. I have a suspicion it's perhaps just a windows / linux issue but will share logs when I have looked at it a bit further.

Using the generated project shared by my colleague, one thing I did notice was the same issue with this line in App:

Logger log = LogManager.getLogger();

If you leave as is you get this CW error:

No class provided, and an appropriate one cannot be found.: java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found.

Logger log = LogManager.getLogger(App.class); resolves the issue.

Everything else appears to work well.

@pankajagrawal16
Copy link
Contributor

Ok great that you got it working. Regarding error on initializing logger, its totally fine to provide class explicitly if log4j is not able to figure it out itself.

I suspect this issue https://stackoverflow.com/questions/52953483/logmanager-getlogger-is-unable-to-determine-class-name-on-java-11 might be related with your project.

Feel free to close the issue if all is good.

@GuyJackson
Copy link
Author

Thanks @pankajagrawal16 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants