Skip to content
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

jetty-maven-plugin logging "scanned from multiple locations" on conflicts between .m2 and WEB-INF directories #6113

Closed
wcedmisten opened this issue Mar 29, 2021 · 6 comments
Assignees
Labels

Comments

@wcedmisten
Copy link

Jetty version 9.4.38.v20210224

Java version Scala 2.11.7

Question How to resolve duplicate class scans between .m2 and WEB-INF jars.

When I run mvn jetty:run, I get copious warnings about classes "scanned from multiple locations". The first location being in my .m2 cache directory and the second being my WEB-INF directory for the webapp I'm trying to test. I believe the WEB-INF jars should be scanned over the .m2 jars, and I was wondering how to configure that behavior.

I found a stackoverflow post which solves a similar issue by excluding the WEB-INF files from being scanned, but that seems backwards to me. Please let me know if I'm missing anything, any help would be appreciated. Thanks!

Partially related to #3190

@joakime
Copy link
Contributor

joakime commented Mar 29, 2021

Did you do anything to alter (or customize) the default server / container / webapp / webinf jar pattern configurations?

@janbartel janbartel self-assigned this Mar 29, 2021
@wcedmisten
Copy link
Author

Do you mean e.g. <webInfIncludeJarPattern> and <containerIncludeJarPattern> under the <webApp> tag?

If that's what you mean, no, we didn't include these in the pom.xml when this behavior was occurring.

Ultimately our solution to remove these warnings was to disable annotation scanning by using an exclusive regex for the above jar pattern tags. We only use web.xml rather than annotations for our project, so this was acceptable.

I'd be happy to try and help if this seems like unexpected behavior or something that needs additional configuration, though.

@janbartel
Copy link
Contributor

@wcedmisten you can also disable annotation scanning by simply making your web.xml metadatacomplete=true. If you use jsps in your project, you will need to keep annotation support in there.

I'm still not clear how you have a multiple copies on the classpath. The jetty-maven-plugin synthesizes the equivalent of WEB-INF/lib by using the maven depenencies for the project. Do you have some jars physcially in your WEB-INF/lib as well as dependencies in the pom? Can you post a sanitized pom.xml?

@wcedmisten
Copy link
Author

I think I figured out what was happening here. For our test process, we build the webapp in one maven command, and then run the jetty maven plugin in another. Apparently, the first step involves copying the webapp files into another directory (I think to integrate them with the frontend code), which is where the duplication was coming from.

My solution was to set <webInfIncludeJarPattern> and <containerIncludeJarPattern> to the directory where the webapp had been copied to, so that only these files are scanned. Does that seem reasonable, or am I missing some way this process could backfire?

@janbartel
Copy link
Contributor

@wcedmisten I think your test process sounds like it needs to be streamlined ;)

mvn jetty:run is designed to be used at the command line, not as part of a build. Thus, for this goal maven runs a parallel build process up to and including the compile-test-classes phase before invoking jetty. You don't want to be doing that if you're trying to bind the execution of jetty to a build phase. You want instead the jetty:start goal. This is designed to be bound to a build life cycle and will not fork a parallel build process to compile your webapp. That is designed to be used with an unassembled webapp (same as jetty:run). If, however, your build process is to first fully build your war, and then later in the build you want to run jetty on that built war, you should be binding the jetty:deploy goal instead. That is designed to be used with a pre-assembled webapp (similar to jetty:run-war) but which does not first try and build your webapp.

@wcedmisten
Copy link
Author

Gotcha, thanks for the information! I'll try to clean up our process.

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

No branches or pull requests

3 participants