Xcode 에서 java(자바) 개발 환경 구축하기(인텔맥 only)

2023. 6. 6. 17:29XCODE

1.https://brew.sh/ 에 접속해 터미널을 이용해 homebrew를 설치한다.

2.터미널에 export PATH=/opt/homebrew/bin:$PATH를 입력한다

cf)1을 한 후에 터미널에 'brew install java 를 입력하고 엔터를 칠 시

command not found 라고 뜨면 2를 행해야 하고 그렇지 않으면 2를 건너뛰어도 된다.

3.'brew install java' 을 터미널에 입력해 java 를 설치해준다.

4.터미널에 where javac 라고 입력한다

5. /usr/bin/javac를 인지하자.

6.Xcode 에서 create a new xcode project 를 누른다

7. other 칸에 external build system 을 누른다

8.product name 과 organization identifier 에 마음에 드는 단어(나의 경우는 boongtol_java)를 쓰고(일치시키면 좋음) build tool 칸에 5번에서 인지한 경로를 그대로 입력한다. 그리고 바탕화면에 저장한다.(create git repository on my mac 은 체크헤제한다.) 그리고 프로젝트 파일 안에서 targets 란에 arguments란에 원래 써져있던 글을 지우고 $(ACTION) $(TARGETNAME).java 를 입력한다.

9. 왼쪽 상단에 file 란에서 new--->file 을 클릭한다. 

10. mac os 란에서 other---> empty 를 클릭한다.

11. 파일 이름을 치라고 뜰텐데 파일 이름에 8번에서 일치시키면 좋다던 단어에다가 .java 추가해 이름을 짓는다.

12. xcode에 product 란에 scheme---> edit scheme에 들어간다.

13. Run 란에 info 탭에 들어가 (debug executable은 체크해제한다.) executable--->other 을 누른 후 command, shift, G 를 동시에 누른다.

14. /usr/bin/java를 입력한다

15. java라는 이름을 가진 unix executable file 을 선택한다.

16. 이제 arguments 탭에 들어가서 arguments passed on launch 에서 +를 누른다.

17. 8번에서 이름을 지었던 파일 이름을 입력한다.(나의 경우에는 boongtol_java.java)

18. arguments 탭에서 enviroment variables 에서 +를 누른다.

19. Name 란에 CLASSPATH 라고 적고 , Value 란에 8번에서 바탕화면에 저장한 폴더 내부에 있는 java 파일의 경로를 적는다.

     (나의 경우에는 /Users/boongtol/Desktop/boongtol_java/boongtol_java.java )

20. options 란에 working directory 에서 use custom working directory 밑에 있는 폴더 모양의 아이콘을 클릭한다.

21. 8번에서 바탕화면에 만든 폴더를 찾아 더블클릭해준다.

22. 이제 설정은 끝났다. 프로그램이 정상 작동해야 한다!

cf)error: source file not found: boongtol_java.java

     Program ended with exit code: 1 

 에러가 뜰 시 터미널에서 pwd를 입력해 얻은 위치에 8번에서 저장한 폴더를 복사(이동)하고 19번에서의 Value 란에 pwd를 입력해 얻은 위치/boongtol_java/boongtol_java.java(나의 경우에는)

즉 나의 경우에는(/usr/local/bin/boongtol_java/boongtol_java.java)이 된다. 또, 20번에 적은대로 하지 말고 pwd를 입력해 얻은 위치에 있는 나의경우(boongtol_java)폴더를 선택해줘야 한다.

 

 

Establishing a java development environment in Xcode (Intel Mac only)

 

1. Go to https://brew.sh/ and install the homebrew using the terminal.
2. Enter export PATH=/opt/homebrew/bin:$PATH in the terminal
After cf)1, type 'brew install java' in the terminal and hit the enter
If command not found appears, you have to do 2 or you can skip 2.
3. Enter 'brew install java' in the terminal to install java.
4. Type where java c in the terminal
5. Recognize /usr/bin/javac.
6.In Xcode, press create a new xcode project
7. Press external build system in the other column
8. Write your favorite word (boongtol_java in my case) in the product name and organization identifier, and enter the path recognized in number 5 in the build tool box. And save it on the desktop.(create git repository on my mac is checked.) In the project file, erase the text originally written in the targets column and the arguments column, and then $(ACTION)$(TARGETNAME).Type java.
9. Click new--->file in the file column in the upper left corner. 
10. Click other--->empty in the macos column.
11. It will say to type the file name, but to the word that matches the file name at number 8.Add java and name it.
12. In the xcode, enter the "product" section into the "system---> edit" scheme.
13. Enter the info tab in the Run field (de-check debug executable.) Press executable--->other and press command, shift, and G at the same time.
14. Enter /usr/bin/java
15. Select the unix executable file named java.
16. Now enter the arguments tab and press + under arguments passed on launch.
17. Enter the name of the file you named in number 8.(In my case, boongtol_java.java)
18. On the arguments tab, under environment variables, press +.
19. Write CLASSPATH in the Name column and java file path in the folder saved on the desktop in number 8 in the Value column.
     (In my case---> /Users/boongtol/Desktop/boongtol_java/boongtol_java.java )
20. Click the folder icon under use custom working directory in the options column.
21. Find the folder you created on the desktop in number 8 and double-click it.
22. Now the setup is over. The program should work properly!
cf)error: source file not found: boongtol_java.java
     Program ended with exit code: 1 
 If an error appears, copy (move) the folder stored in number 8 to the location obtained by entering pwd at the terminal and the location obtained by entering pwd in the Value column at number 19/boongtol_java.java (in my case)
That is, in my case (/usr/local/bin/boontgol_java/boontgol_java).java). In addition, you should select the folder (boontgol_java) in the position you obtained by entering pwd instead of doing what you wrote in number 20.