问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/45370986/how-to-run-java-9-application-with-classpath-rather-than-module-path-in-idea