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?
2 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.

- 557
- 5
- 17
-
2I understood the question to mean that he prefers to run the entire project from the class path. Why? Who knows, maybe to test compatibility. Maybe to evade problems with dependencies that are not fit to be turned into automatic modules (e.g. because they split a package). – Nicolai Parlog Jul 28 '17 at 17:51
-
1I don't think the question is answered - as far as I can see, IntelliJ offers no option to use classpath instead of the module path when using JDK9. And the reason for doing this? Practically the entire Java ecosystem is incompatible with modules - there are split packages in all major open source projects, invalid module names (any jar with the word native in it for example, such as netty, cassandra etc) all over the place. Working with modules right now is an uphill battle that no one wants to fight. – James Roper Feb 27 '18 at 23:51
To answer the question, the heuristic IDEA uses to run an application with a module path is currently slightly off (IDEA 2018.01). It apparently takes more into consideration than it should.
See IDEA-187390 and IDEA-193714 for details.
So if your current project does not have a module-info file and you still end up with a module path the current case that I know is that you are running the main class from a dependency. Just build a small wrapper inside your project and run the main class from there, that brings you back to the classpath.

- 8,601
- 4
- 24
- 24