programming

Gradle을 이용해 만든 자바 프로그램 실행시 "Could not find or load main class 클래스이름"에러 발생

programmer j 2017. 8. 4. 11:45


IntelliJ IDEA에서 gradle를 이용해 만든 자바 프로그램을 도스 콘솔창에서 실행할 때 "Could not find or load main class 클래스이름"에러 발생한다.


개발환경

- Windows 10 Pro 64-bit English

- IntelliJ IDEA COMMUNITY 2017.2


증상
IntellJ IDEA IDE에서는 정상적으로 실행됨
installDist태스트로 만든 실행파일을 도스창에서 실행하면 "Could not find or load main class 클래스이름"에러 발생


원인

build.gradle파일의 mainClassName항목에 패키지 이름을 포함한 클래스 이름을 써주지 않아서 발생한다.

(main 메쏘드가 있는 클래스 이름만 써주면 에러 발생)


예)


ExampleClass.java

package example.sphinx4;

:

public class ExampleMain {
  :
}

 
Could not find or load main class ExampleMain 에러가 발생하는 build.gradle파일

apply plugin : 'java'
  :
mainClassName = 'ExampleClass'


정상적으로 실행되는 build.gradle파일

apply plugin : 'java'
  :
mainClassName = 'example.sphinx4.ExampleClass'