Note: I have ran the program in IntelliJ without error, I need to make it independent of IDE, i.e. run it under command line. I got the error not because I didn't implement it, but I didn't understand how I can let compiler know it.
I have a project composed of 7 to 10 java files, relies on 5 jar files. The project is managed in IntelliJ project, version 2017.1.
Now I want to run a java class with a main function from the project. In the command line of local computer, I run the class with script:
/project/out/path> java retrieve_result
I correct my script as How to run java program in command prompt,created by intellij .
Note: in the retrieve_result
class, there are dependencies on other java and jar files.
The error is shown as below:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/store/Directory
at HW2MainLucene.ReadIndex(HW2MainLucene.java:69)
at HW2MainLucene.main(HW2MainLucene.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.store.Directory
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@9-internal/BuiltinClassLoader.java:366)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@9-internal/ClassLoaders.java:184)
at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:419)
... 2 more
As far as I have learned, this error comes because the compiler cannot locate the jar files. But in the IntelliJ project, it is already configured.
How can I configure the compiler to get a usable program?