-
Notifications
You must be signed in to change notification settings - Fork 86
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
Problem with maven compilation. #370
Comments
We are getting the same error when we try to run the Javadoc tool on our module project. The error message is a little bit cryptic, but the cause of the error is that the current I don't think you can really do much (other than modifying the JAR itself or perhaps manually putting |
Hey, sorry, I was away on Vacation. Out of curiosity, do you have This is where the class is located: The logging-api JAR needs to be on the same module/classpath as Rewrite Servlet. (I would also guess any other ocpsoft/rewrite JAR would also need to be in the same module/classpath. Let me know if that helps? I don't think moving the JDKLogAdapterFactory into rewrite-servlet.jar is the right solution. |
Unfortunately, I don't think that's enough. If one uses the module system, when a module ( For example, https://docs.oracle.com/javase/specs/jls/se11/html/jls-7.html#jls-7.7.4
|
What about the opposite? It should be enough to move the |
That would essentially force all dependents who use The solution (as I understand it) is to make sure that rewrite-servlet.jar and ocpsoft-logging.jar are both in the same module. Is this not possible for some reason? Per the docs you linked: |
Note the difference between
Unless I'm completely mistaken: A "module" here refers to a JPMS (Java Platform Module System) module, not a Maven project or runtime environment. It's not enough to load all modules to the module path, the service provider must be declared within the same JPMS module. JPMS preserves the boundaries between modules even at runtime. E.g.
So if I understand the intention correctly, it should default to It would require some refactoring, but another solution I can think of is to extract Or perhaps, as a workaround, it's possible to add a dummy implementation of |
Yeah, that's right. In most module systems I've used in the past, developers have control over which artifacts (JARs and Classes) are actually loaded into a specific module. This can generally be done via the Module System configuration files. It sounds like your JPMS is setting each ocpsoft Maven artifact JAR to be in its own module. Which, while possibly reasonable by default, is probably not right in this case. The JPMS system should be configured such that all Ideally rewrite would have module-info.java files to make it modular, but unless someone is volunteering for that, the PS. It also sounds like it's fine for service implementations to be in separate jars from their loader configuration, but in the JDK9 module system, those implementations need to be exported via module-info.java and marked as explicitly "provided" (e.g. ocpsoft-logging). Then "used" in the dependent module (in this case rewrite-servlet.jar). (See https://www.baeldung.com/java-9-modularity). So this is part of the work that would need to be done to add module descriptors to Rewrite. |
I've been working with JPMS a bit, so let me try to explain. First of all,
provides org.ocpsoft.rewrite.spi.LogAdapterFactory with JDKLoggingAdapterFactory The The module must use ServiceLoader to find the implementations of a
That's how JPMS is designed (to ensure encapsulation), there's no other (proper) way. The
To clarify: the unnamed module doesn't exist, there are multiple unnamed modules for different JARs. Essentially that just means placing But don't get me wrong: That's completely reasonable for now, it takes time to make changes in a large project. My only worry with this workaround, though, is that it's a bit cumbersome, as it means having to tinker with Java options, which can't be set by library authors, but need to be set by end users who, in one way or another, happen to include PS: This is not (yet) a problem for us, as (a) we can't switch to modules for some time to come due to many dependencies that are not yet compatible with the module system, (b) we only noticed this when we attempted to create JavaDocs in a modular environment, an attempt which we had to abort for various other reasons. |
Yeah, my experience is with OSGI and JBoss Modules. I have not used JPMS so I'm just reading the docs here right now. Thanks. Our understanding of
Right. So in JPMS does that mean the service-loader's
Right.
Yes: https://github.com/ocpsoft/logging/blob/master/api/src/main/java/org/ocpsoft/logging/Logger.java#L326 (And the service being loaded is both implemented and declared (in META-INF/services) in the same JAR, here.
Yes. I agree. This is the same in other systems. And we are definitely talking about backwards compatibility here :)
Right. It's basically "default" for any artifact without a
Cool. I would like to make sure this gets fixed though, so definitely welcome the fix once we land on it. That said, I have a new idea about what is wrong. See below.
Agreed, it is not ideal. OK. Now on to my new realization about what's wrong here. The I am concerned that if what you're saying is true, that Rewrite simply isn't compatible with the JDK module system, since if I'm understanding you correctly, services must be both 'provided' and explicitly 'used' by other modules in order to show up to the If that's the case, then none of the Rewrite integration/extension modules will ever work in the JDK module system, since they are supposed to be "add-ons" that can be simply added to the classpath and they self-register their extensions. (via service providers.) The JDK module paradigm would completely break the rewrite extension model. I feel like there's something we're missing here. |
Great, I was almost done with my answer the my notebook decided to crash...
Glad we're on the same page, I very much support it if you want to fix it : )
Yes, you only need the The only restriction here is that you can't have a service provider in module On a side note, I can't count the times I had to debug into
Yes that should work. If that's how it was supposed to be anyways, that's probably the best (and proper) solution for now. In the long term run, though, I'm not sure if uber JARs are a good idea for the module system. I don't have much experience with modular uber JARs. It should be possible in principle, but see also this Jigsaw spec issue regarding Either way, that only applies once you add proper
I think it should work, if I understand the use case correctly. Perhaps I didn't explain it well enough. It might be easier to illustrate with an example:
Now with that setup, a consumer can include
Not sure if it's relevant for this project, but another important unnegotiable requirement to keep in mind is: There must be no overlapping packages, i.e. there can't be any two modules that have a class in the same package ("sub" packages count as different packages). Otherwise it's just not compatible with the module system. |
Hey @blutorange, thanks for this update/in-depth reply. It totally sucks when that happens and you lose everything you typed :(
Yes, I do!
Hmmm.... does it? Assuming the current packaging structure, and the following scenario:
If this works (and once the logging JAR situation is resolved), then I think we can add a ======================================== Alternately... Let's say we add What's the real work in doing that? Just crafting these files? What else would be required? ======================================== Related, a couple folks have started a similar update for the OCPsoft PrettyTime library, here: They are recommending the Moditect Maven Plugin, what are your thoughts about using this plugin for the Rewrite side of things? Could we possibly auto-generate the |
Yeah, that sounds reasonable to me. Basically
Yes again, that sounds reasonable, but two points to keep in mind:
Regarding the possibility of the uber JAR, there's one question I think that needs to be answered: What about the the case where both I could imagine some project that includes So either we can say that such a scenario is unlikely to occur and/or is unsupported; or the uber JAR approach won't work. Packages such as
Writing the And of course, as mentioned in that prettytime thread, if you want to support Java 8, you need create a multi release JAR (which too shouldn't be too hard to setup, but needs to be tested as well).
I know about that plugin, but I haven't used it much in my projects personally. Each tool adds additional complexity (and bugs). And the projects that I set up as modules weren't large enough to be worth the effort. One thing you definitely can't do is completely auto-generate the module-info.,java just from the information in a normal Maven pom.xml. It will require at least some amount of hand-crafting, at least for more complex projects (e.g. it couldn't possibly know what you want to If you take a look at the usage section of the moditect plugin, you'll see it has a long In the end, that plugin is just a different way of creating a module-info.java. If it makes it easier, then by all means go for it. But I'd probably start with writing the |
When i compile my project from Eclipse everything is OK, but if i ran maven i obtain this error:
E:\programy\aikrepo\aik-cms>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< aikweb:aikweb >----------------------------
[INFO] Building aikweb 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- resources:3.3.0:resources (default-resources) @ aikweb ---
[INFO] Copying 23 resources
[INFO]
[INFO] --- compiler:3.10.1:compile (default-compile) @ aikweb ---
[WARNING] Can't extract module name from rewrite-servlet-6.0.0-SNAPSHOT.jar: Provider class org.ocpsoft.common.logging.JDKLogAdapterFactory not in JAR file rewrite-servlet-6.0.0-SNAPSHOT.jar
[INFO] Required filename-based automodules detected: [weld-servlet-shaded-5.1.0.Final.jar, log4j-1.2.17.jar, commons-io-2.4.jar, xercesImpl-2.11.0.jar, qrgen-1.4.jar, commons-codec-1.9.jar, commons-validator-1.4.0.jar, json-lib-2.4-jdk15.jar, commons-lang-2.5.jar, javax.mail-1.5.0.jar, activation-1.1.jar, zt-zip-1.15.jar, jakarta.faces-4.1.0-SNAPSHOT.jar, rewrite-integration-faces-6.0.0-SNAPSHOT.jar, commons-dbcp2-2.9.0.jar, primefaces-12.0.0-jakarta.jar]. Please don't publish this project to a public artifact repository!
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1438 source files to E:\programy\aikrepo\aik-cms\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /E:/programy/aikrepo/aik-cms/src/main/java/module-info.java:[24,21] module not found: rewrite.servlet
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.988 s
[INFO] Finished at: 2023-03-31T18:18:38+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project aikweb: Compilation failure
[ERROR] /E:/programy/aikrepo/aik-cms/src/main/java/module-info.java:[24,21] module not found: rewrite.servlet
If i remove my module-info.java file then it is ok and maven compiles my project.
This is my module-info.java
`module aikweb
{
}
And POM
4.0.0
aikweb
aikweb
0.0.1-SNAPSHOT
war
`
What can I do?
The text was updated successfully, but these errors were encountered: