#Package ambiguity in java 9 modules.

1 messages · Page 1 of 1 (latest)

viral wolf
#

I'm trying to convert my java project to modules(JPMS), One package is exist in two of my jars so i can't make build of it, How to resolve this issue, (I cant work on refactoring those jars)

summer lavaBOT
#

<@&987246452180930620> please have a look, thanks.

thin bear
#

your options are

#
  1. Make a third jar with the package
  2. Rename the package in one or both jars
  3. 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

viral wolf
#

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.

thin bear
#

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

viral wolf
#

I use intellij, and i have place my jars under libraries then enabled in Modules > Dependencies.

thin bear
#

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

viral wolf
thin bear
#

you can't use them as modules because there are split packages between the jars

viral wolf
thin bear
#

that is what i am referring to

viral wolf
#

If they've resolved things means, Then we can directly require them on our module right ?

thin bear
#

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

viral wolf
#

No we dont use maven/grade

#

We use tomcat with war

thin bear
#

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

#

so your module-infos won't take effect

#

and none of your deps would go on the module path

viral wolf
#

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 ?

thin bear
#

err

#

🤷‍♂️

#

ask me again in the morning

#

(its 2am rn)

#

there certainly isn't a downside to having module-infos

viral wolf
viral wolf
honest crest
#

But I recommend checking out The Java module system or Java 9 modularity.

summer lavaBOT
#

Closed the thread.

summer lavaBOT
#

@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 👍