#-cp vs --module-source-path

1 messages · Page 1 of 1 (latest)

fair otter
#

My understanding is as follows:

In a multimodule-java project, it's compiled using

javac --module-source-path modulesdir -d out --module ModuleA,ModuleB..

and run using

java --module-path modulesdir --main-module ModuleA

does this mean that I never need to use the -cp option when working with multimodule java projects?

left oakBOT
#

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

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

Your understanding is partially correct.

In a multimodule Java project, the --module-source-path option is used to specify the directory where the source code for all modules is located. It is not used for compilation, but rather for locating the source files.

To compile the modules, you would use the javac command with the -d option to specify the output directory and --module option to specify which modules to compile.

The correct command would be:

javac --module-source-path modulesdir -d out --module ModuleA,ModuleB

Here, modulesdir is the directory containing your module source files, out is the output directory where compiled classes will be placed, and ModuleA and ModuleB are the names of the modules you want to compile.

It's worth noting that in Java 9 and later versions, you can also use the -cp or --class-path option to specify additional classpath entries if needed. This allows you to include external dependencies or libraries required by your modules during compilation.

fair otter
#

oh alright. then wont that mean that for java 9+, -cp is rarely ever used?

stuck axle
#

enough popular libraries are not modularized that most people still use --class-path or -cp

#

the module system isn't really widely adopted except in places where you are forced to interact with it like JavaFX

#

you can split libraries between the class path and module path, but tooling doesn't support that too well

stuck axle
#

but yes if you put your stuff on the module path (and even non modular libraries will usually work there) then you don't need --class-path

fair otter