Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Java 9 application with classpath rather than module path in IDEA?

When I run a main class in IDEA, it puts the module and its dependencies on a module path. Is it possible to change it to a classpath?

like image 235
ZhekaKozlov Avatar asked Oct 19 '25 09:10

ZhekaKozlov


1 Answers

If you don't define a module-info, IDEA would set the application and your dependencies on the classpath. Since you have a module-info it's an explicit module so it has to be on the module path. Normally you would handle your dependecies now as automatic-modules.

Howsoever, your dependencies at least have a good reason to be on the classpath. We discussed that here Why Java 9 does not simply turn all JARs on the class path into automatic modules?

For example, mymodule depends on an automatic-module which however needs a jar that can't become an automatic-module yet. On commandline it would like this:

java -cp legacy.jar -p "mymodule.jar;automodule.jar;" -m mymodule/com.example.mymodule.Application

IMO intellij doesn't currently support that. As a workaround to run the entire application on the classpath at least, you could rename the model-info for disabling/not to be a jigsaw-module for a moment.

like image 77
Daniel Avatar answered Oct 21 '25 22:10

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!