본문 바로가기

[IT/Programming]

Installing and Learning JAVA

반응형
# Installing and Learning JAVA JAVA를 깔고 배워봅시다. (자바 깔고 배우기.) ## PH
  • 2023-06-26 : Links updated.
  • 2022-12-18 : revised.
  • 2019-04-01 : First posting.
## TOC ## Installing JAVA Oracle 홈페이지 에서 적절한 파일 (.exe) 다운 받아서 실행시키기만 하면 설치 끝. 기본적으로는 window %PATH% 와 %CLASSPATH% 를 설정해줘야 함. 이 설정은 cmd 창에서 하기 보단 "내 컴퓨터 - 설정 - ..." 에 가서 하는게 더 편해보임. 아래와 같은 경로들을 추가해 주면 끝. 뭐 batch 파일에서 몇개는 경로설정을 해줘서 따로 이 설정을 안해줘도 되는 것들도 있긴함. (e.g. CLASSPATH) ```[.linenums.lang-bat] %JAVA_HOME%=C:\Program Files\Java\jdk1.8.0_05 %PATH%=.......;%JAVA_HOME%\bin; %CLASSPATH%=.;%JAVA_HOME%\lib\;C:\(class folder path)\classes ```/ ## Build system in Sublime Text 3 Eclipse 가 좋은면이 있는거 같긴한데, Sublime Text 도 나름대로 장단점이 있어서 삽질을 해가며 build system 을 만들어 봤음. 우선 sublime-text 3 에서 "Preferences - Browse Packages" 로 package 들이 깔린 폴더로 들어가고 User 폴더안에 "runJavaC.sublime-build" 파일을 만들어 다음과 같은 JSON (JavaScript Object Notation) 을 넣고 저장함. ```[.linenums] { "cmd": ["runJava.bat", "$file"] // , "file_regex": "^(...*?):([0-9]*):?([0-9]*)" , "selector": "source.java" , "encoding": "utf-8" // "cp949" } ```/ .java 형태의 파일을 build 할때 runJava.bat 파일로 실행시키겠다는 것임. (file_regex 도 집어넣던데 뭔지 잘 모르겄음. 없어도 잘 돌아가긴 함.) 그렇다면 runJava.bat 파일을 만들어줘야 할텐데, 다음과 같이 만들어서 java.exe 가 있는 폴더에 넣어주면 됨. (폴더명에 한글이 있을경우 batch 파일 인코딩은 EUC-KR 같은걸로 윈도우 한글 인코딩이랑 맞춰줘야 함.) Batch file 이나 shell script (Mac) 관련해서는 참조. ```[.linenums.lang-bat] @REM encoding must be EUC-KR with Korean folder name. @ECHO OFF :: destination of class to be created SET DC=C:\Recoeve\classes :: The whole CLASSPATH list splited by ";" SET CLASSPATH=.;C:\Program Files\Java\jdk-17.0.2\lib;C:\Recoeve\classes;C:\Recoeve\classes\javax.mail.jar;C:\Recoeve\classes\mysql-connector-java-8.0.19.jar;C:\Recoeve\classes\activation-1.1.1.jar;%VERTX_HOME%\conf;%VERTX_HOME%\lib\* :: %~nx1 expands %1 [arg 1] to "file name + extension". e.g. "HelloWorld.java" ECHO Compiling %~nx1 :: Compile %~nx1 with {filename:%~nx1, encoding:utf8, destination:%DC%, classpath:%CLASSPATH%} javac %~nx1 -encoding utf8 -d "%DC%" -classpath "%CLASSPATH%" IF NOT %ERRORLEVEL%==0 GOTO :EOF :: source directory SET SD=%CD% @REM or SET SD=%~dp1 :: %SD%\%~n1 gives [source directory]\file_name. e.g. "C:\Recoeve\sources\kipid\hello\HelloWorld". SET packSD=%SD%\%~n1 @REM or SET packSD=%~dpn1 :: Replace "C:\Recoeve\sources\" to "" [empty] of %packSD%. e.g. "kipid\hello\HelloWorld". SET CN=%packSD:C:\Recoeve\sources\=% :: Replace "\" to "." of %cn%. e.g. "kipid.hello.HelloWorld" :: This is a class name with JAVA package included. SET CN=%CN:\=.% ECHO --- OUTPUT: %CN% %2 %3 %4 %5 %6 %7 %8 %9 --- :: Change directory to the %DC% [destination of class to be created]. CD %DC% :: Run/Execute the class created. java -Dfile.encoding=UTF8 -classpath "%CLASSPATH%" %CN% %2 %3 %4 %5 %6 %7 %8 %9 :: Back to source directory CD %SD% ```/ 대충 compile 할 때 -encoding (UTF-8) 이랑, -sourcepath, -d (destination) 폴더 설정해 준 것이고. Compile 이 error 없이 잘 끝났다면, source folder 경로를 분석해서 어느 package 인지 알아내고 실행시켜주는 batch file 임. 즉 ".java file" 의 첫줄이 package com.example.hello; 라면, 이 파일은 "C:(source folder path)\sources\com\example\hello" folder 에 있어야 제대로 돌아감. 제대로 된 폴더에 ".java file" 이 있었다고 할 때, 이 파일을 compile 하면 "C:(class folder path)\sources\com\example\hello"에 ".class" file 이 만들어지고 실행 됨. 실행은 "C:(class folder path)\classes" folder 에서 "java com.example.hello.(ClassName) args" 형태로 실행되는 것임. 참조: . ## RRA

    Official

  1. oracle.com :: Java > Technical Details > Java Downloads, 2023-06-26 기준: Java 20 and Java 17 available now
    // x64 Installer :: 159.95 MB :: https://download.oracle.com/java/20/latest/jdk-20_windows-x64_bin.exe (sha256)
    // Windows 에서는 .exe file 로 까는게 속편하긴 한듯.
  2. IDE (Integrated Development Environment)

  3. www.eclipse.org/downloads
    // eclipse-jee-kepler-SR2-win32-x86_64.zip (250MB), 2014-06-09
  4. http://www.sublimetext.com/; JAVA 관련 package 좋은거 뭐 없나?
  5. Tutorial

  6. docs.oracle.com :: JDK 20 Documentation;
    and docs.oracle.com - The Java™ Tutorials; and Java Tutorials Learning Paths; and Trail: Learning the Java Language
  7. http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html; javac의 [options].
  8. Documentation and API Reference

  9. Documentation - http://docs.oracle.com/javase/8/index.html
  10. API Reference - http://docs.oracle.com/javase/8/docs/api/index.html
  11. Etc.

  12. Wiki - Batch file; and wikibooks.org - Windows Batch Scripting; 어렵진 않은거 같은데, 따로 공부하기가 심히 귀찮은... 대충 "%"만 검색해보고 "%~nx1", "%sp%" 같은 놈들 쓰임새만 파악하면 여기 있는 batch file 이해하는데에는 충분할듯도.
  13. kipid's blog :: Sublime Text (editor) 소개
  14. kipid's blog :: Compiling and Running JAVA (Build System) through batch (.bat) and shell script (.sh)
반응형