2018년 11월 1일 목요일

[TroubleShooting] sbt could not find or load main class file

Have you gotten this error message, when you execute sbt in git bash?

Error: Could not find or load main class file
Caused by: java.lang.ClassNotFoundException: file


But the problem is that it works in Windows CMD, but it doesn't work only git bash

So I tried to find solution in google, and I got a solution like this
In short, Change the path that "C:\Program Files" to "C:\Progra~1" and "C:\Program File(x86)" to "C:\Progra~2". because git shell can't recognize space and special character such as () in path.

So I generated environment varaibles like below

And I changed SBT and Git path to the variables.

But It still doesn't work

So I found another way and I did it.(another way)
In short, you should execute sbt.bat not sbt

It works fine!


But typing sbt.bat is so annoying, I wanted to type only "sbt"

So I set alias in git bash like below

$> vi ~/.bashrc

Add "alias sbt 'sbt.bat'" in .bashrc
Apply the script
$> source ~/.bashrc

Now, It works even if you type "sbt"

[TroubleShooting] git bash에서 sbt로 프로젝트 생성이 안되는 증상

Error 내용은 다음과 같다

Error: Could not find or load main class file
Caused by: java.lang.ClassNotFoundException: file


그러나 윈도우 기본 터미널인 cmd에서는 잘 동작한다.

Git bash에서 할 수 있는 방법을 찾던 중, 구글링 결과 다음과 같은 해결책을 제시해주었다.(링크)
요점은, 일반적으로 윈도우에서 인스톨시 C:\Program Files나 C:\Program Files(x86)에 인스톨하는데 여기 띄어쓰기와 괄호가 문제라는 것이다. 그래서 이를 C:\Progra~1, C:\Progra~2로 바꾸라는 것이다.

그래서 시키는데로 했다. 먼저 두 환경 변수를 만들고,


Path에 sbt를 저 환경변수로 바꿔주었다

그러나 여전히 똑같은 에러가 난다...

다른 방법을 찾아 헤매다가 다음을 발견했다.(링크)
요점은 windows에서는 sbt가 아니고 sbt.bat를 실행하라는 것이다.

잘 동작한다!


매번 sbt.bat를 치는건 귀찮으니, git bash의 alias를 추가하기로 한다.
$> vi ~/.bashrc

alias sbt 'sbt.bat'를 추가한다.
$> source ~/.bashrc를 통해 적용한다.

이제 sbt로도 잘 동작한다!


[TroubleShooting] sbt could not find or load main class file

Have you gotten this error message, when you execute sbt in git bash? Error: Could not find or load main class file Caused by: java.lang....