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 - jetty:run does not work with pom type dependencies #12173

Closed
jaygarala opened this issue Aug 19, 2024 · 10 comments · Fixed by #12177
Closed

Jetty Maven Plugin - jetty:run does not work with pom type dependencies #12173

jaygarala opened this issue Aug 19, 2024 · 10 comments · Fixed by #12177
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@jaygarala
Copy link

Upgrading from Jetty 9.4 to 12

Jetty version(s)
Jetty 12

Jetty Environment
ee10

Java version/vendor (use: java -version)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)
Apache Maven 3.6.3

OS type/version
Ubuntu 22

Description
This is working with Jetty 9.4. We have a maven dependency in the web-app that is <type>pom</type>, more details here. When running with jetty:run, we get the following error.

[INFO] jetty-12.0.12; built: 2024-07-25T21:58:37.668Z; git: cc6f1b74db755fed228b50701ad967aeaa68e83f; jvm 17.0.12+7-Ubuntu-1ubuntu222.04
[WARNING] Invalid Resource Reference: jar:file:/home/jay/.m2/repository/org/example/ext-maven-deps/1.0-SNAPSHOT/ext-maven-deps-1.0-SNAPSHOT.pom!/
[WARNING] Failed startup of context oeje10mp.MavenWebAppContext@6909f6be{ROOT,/,b=file:///home/jay/projects/temp/jetty-maven-proj/webapp/src/main/webapp/,a=STOPPED,h=oeje10s.SessionHandler@6b5ab2f2{STOPPED}}{file:///home/jay/projects/temp/jetty-maven-proj/webapp/src/main/webapp/}
java.lang.IllegalArgumentException: Unable to mount FileSystem from unsupported URI: jar:file:///home/jay/.m2/repository/org/example/ext-maven-deps/1.0-SNAPSHOT/ext-maven-deps-1.0-SNAPSHOT.pom!/
    at org.eclipse.jetty.util.resource.FileSystemPool.mount (FileSystemPool.java:135)
    at org.eclipse.jetty.util.resource.ResourceFactoryInternals$CompositeResourceFactory.mountIfNeeded (ResourceFactoryInternals.java:268)
    at org.eclipse.jetty.util.resource.ResourceFactoryInternals$CompositeResourceFactory.newResource (ResourceFactoryInternals.java:225)
    at org.eclipse.jetty.util.resource.ResourceFactoryInternals$Closeable.newResource (ResourceFactoryInternals.java:145)
    at org.eclipse.jetty.util.resource.ResourceFactory.newResource (ResourceFactory.java:331)
...
Caused by: java.nio.file.ProviderNotFoundException: Provider "jar" not found
    at java.nio.file.FileSystems.newFileSystem (FileSystems.java:359)
    at java.nio.file.FileSystems.newFileSystem (FileSystems.java:288)
    at org.eclipse.jetty.util.resource.FileSystemPool.mount (FileSystemPool.java:116)
    at org.eclipse.jetty.util.resource.ResourceFactoryInternals$CompositeResourceFactory.mountIfNeeded (ResourceFactoryInternals.java:268)
    at org.eclipse.jetty.util.resource.ResourceFactoryInternals$CompositeResourceFactory.newResource (ResourceFactoryInternals.java:225)
    at org.eclipse.jetty.util.resource.ResourceFactoryInternals$Closeable.newResource (ResourceFactoryInternals.java:145)
    at org.eclipse.jetty.util.resource.ResourceFactory.newResource (ResourceFactory.java:331)

How to reproduce?
Extract the sample project. Run mvn install, then cd webapp, and mvn jetty:run

jetty-maven-proj.zip

@jaygarala jaygarala added the Bug For general bugs on Jetty side label Aug 19, 2024
@joakime
Copy link
Contributor

joakime commented Aug 19, 2024

jetty-maven-plugin gets its dependencies directly from maven.
Maven is the one doing the resolution and handing it to the maven plugin.

@jaygarala
Copy link
Author

Here is a similar sample project with Jetty 9.4
jetty9-maven-proj.zip

@janbartel
Copy link
Contributor

@jaygarala thanks for the report. I've raised #12177 to fix it.

@olamy
Copy link
Member

olamy commented Aug 20, 2024

@jaygarala FYI using such dependency is deprecated in Maven, tend to generate some problems and might be removed in the coming Maven 4.
You should use a BOM strategy.
See this https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms (as you can see the trick you are using is not even documented :)

@pzygielo
Copy link
Contributor

(as you can see the trick you are using is not even documented :)

Seems exactly this to be documented in linked book by sonatype.

@olamy
Copy link
Member

olamy commented Aug 20, 2024

(as you can see the trick you are using is not even documented :)

Seems exactly this to be documented in linked book by sonatype.

sonatype != Apache Maven dev

btw that's probably outdated doc which need to be fixed.
@pzygielo what is the link?

@pzygielo
Copy link
Contributor

In description, under more details here.

@olamy
Copy link
Member

olamy commented Aug 20, 2024

@pzygielo thanks.
so definitely not an official documentation from the Apache Maven project :)
anyway issue fixed, advice to use better practice.

@jaygarala
Copy link
Author

jaygarala commented Aug 21, 2024

@jaygarala FYI using such dependency is deprecated in Maven, tend to generate some problems and might be removed in the coming Maven 4. You should use a BOM strategy. See this https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms (as you can see the trick you are using is not even documented :)

This is not a 'trick', it is documented here, known as Grouping Dependencies. You include the POM as your dependency and it will bring the declared dependencies into your project.

The BOM strategy is used to define the specific version of dependencies that you are including in the Maven module/sub-modules. You would still need to include the individual dependency in your module.

Also the issue is of a third-party dependency which we have no control over.

@olamy
Copy link
Member

olamy commented Aug 21, 2024

As said earlier you are reading some outdated documentation from a software vendor, this is not official documentation from the Apache Maven project.
Look at this page https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms as you can see this trick is not even documented for good reason.

You would still need to include the individual dependency in your module.

Yes and this is a golden rule of using Maven always declare dependencies you are using if you want real control of your dependencies.
Do not rely on transitive dependencies as they can be change or worst adding a new dependencies can change all the tree and you may some dependencies/version you don't want.
Golden Rule again: you use a dependency declare it.

I'm saying with my hat of Maven developers to help you.
If you still have some doubt feel free to ask if it's a good practice on the user mailing list https://maven.apache.org/mailing-lists.html (I'm curious to see the answers :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants