#Package ambiguity in java 9 modules.
1 messages · Page 1 of 1 (latest)
<@&987246452180930620> please have a look, thanks.
The Java module system does not allow for split packages
your options are
- Make a third jar with the package
- Rename the package in one or both jars
- Combine the jars
I cant work on refactoring those jars
Why not?
you are gonna have to change some stuff to make it work no matter what
Make a third jar with the package is that easy for long run ? Is there any tools does that unification automatically?
Why not? There were several teams working on that dependencies(jar), so making them to work for us is kinda painful job, as they are not in process to support modules for now.
if you are thinking of scripting it...eh? i wouldn't. You can make it work in the long run in a few ways
i.e. by making an aggregator module
but the easiest thing is going to be to start putting dependencies on the module path and leave those + your app on the class path until you can resolve it
Cant get it ethan, Could u please explain it clearly
I use intellij, and i have place my jars under libraries then enabled in Modules > Dependencies.
okay so lets say your app has three dependencies
apple.jar, banana.jar, and carrot.jar
if you were in the situation where all three didn't have split packages, you could make everything a module
and you could do this, to start, by just putting everything on the module path
java --module-path libs/apple.jar;libs/banana.jar;libs/carrot.jar ...
without module descriptors, apple, banana, and carrot would be "automatic modules"
meaning their module name would come from the jar name
but you can still modularize your app with that
module app {
requires apple;
requires banana;
requires carrot;
}
so you would compile app.jar and run with it on the module path too
java --module-path libs/apple.jar;libs/banana.jar;libs/carrot.jar;libs/app.jar -m app/app.Main
and then you would go in to apple, banana, and carrot
and add explicit module descriptors as you are able
module org.apple {
exports apple;
}
then once everything has an explicit module info and you are running from the module path you've done it
but your problem is that your equivalent of apple and banana export the same package
this is not allowed on the module path
but it is allowed on the class path
so you can still put carrot on the module path
java --module-path libs/carrot.jar
but apple and banana need to live on the class path until you fix the split package
java --module-path libs/carrot.jar --class-path libs/apple.jar;libs/banana.jar
which means that your app can't get a module info
and needs to live on the class path as well
to manually resolve this you can crush apple and banana in to one jar yourself
applebanana.jar
and then require it from your app module
module app {
requires applebanana;
requires carrot;
}
and once apple and banana figure their shit out and you want to use them directly, you can make your own module info
module applebanana {
requires transitive apple;
requires transitive banana;
}
and make an "aggregator module"
assuming you wanted to keep code that requires the applebanana module you just made working as-is
Once they fixed things, they can be used as modules right ? So why we cant use them like a module , cause because that needs some effort ?
that wasn't english
you can't use them as modules because there are split packages between the jars
Wdym by their figure out things, I thought they were resolving the split packages
yes
that is what i am referring to
If they've resolved things means, Then we can directly require them on our module right ?
yes
they might be automatic modules
but you'd be able to require them in your module
and until they do, you either need to make your own special applebanana.jar or you cannot have a module-info for your app
but you could put some of your dependencies on the module path
as always, I can give better advice the more specific info i have
but im also curious what situation you are in that you are able to just download the jars to a folder
and aren't using maven/gradle + an internal company repo
hmm
well if tomcat is loading your app, there is a decent chance you might not be able to put anything on the module path
but idk really
yeah...digging in to it a lil
Tomcat opens wars on the classpath
or at least it did as of this stack overflow post https://stackoverflow.com/questions/46618118/web-inf-lib-directory-vs-java-9-modules
so your module-infos won't take effect
and none of your deps would go on the module path
For now our need for module is to class usage restriction so even though no support for modular deployment, We can build the modular jars right ? So we can restrict the developers from not allowed classes right ?
err
🤷♂️
ask me again in the morning
(its 2am rn)
there certainly isn't a downside to having module-infos
So not using in deployment in tomcat is not a problem right ?
It's 11:40 AM in india :ew: xD, Good Night Bro 🌃
For a high level view: https://www.baeldung.com/java-modularity section 4
But I recommend checking out The Java module system or Java 9 modularity.
This tool can also help you get going: https://github.com/moditect/moditect
Closed the thread.
@viral wolf
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure 👍