๐ŸฆMaven

Java ๊ธฐ๋ฐ˜์˜ ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ, ์ปดํŒŒ์ผ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋นŒ๋“œ ๋„๊ตฌ์ด๋‹ค. ๋นŒ๋“œ์‹œ ํ…Œ์ŠคํŠธ๋ฅผ ๋ณ‘ํ–‰ ์ˆ˜ํ–‰ ํ•˜๊ฑฐ๋‚˜ ์„œ๋ฒ„ ์ธก deploy ์ž์›์„ ๊ด€๋ฆฌ ํ•  ์ˆ˜ ์žˆ๋‹ค. Maven์˜ ์ฃผ๋œ ๋ชฉํ‘œ๋Š” ์ตœ๋‹จ์‹œ๊ฐ„๋‚ด์— ๊ฐœ๋ฐœํ•œ๊ฒƒ์˜ ์ „์ฒด ์ƒํƒœ๋ฅผ ์ดํ•ด ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š”๊ฒƒ์ž…๋‹ˆ๋‹ค. - ๐Ÿ“ What is Maven?

๐Ÿ”ง ์˜์กด์„ฑ ๊ด€๋ฆฌ

/pom.xml


	<dependency>
		<groupId>org.mariadb.jdbc</groupId>
		<artifactId>mariadb-java-client</artifactId>
		<version>2.0.1</version>
				...
	</dependency>

  • properties - ํŠน์ • ๊ฐ’์„ ๋ฐฐํฌ ํ™˜๊ฒฝ์— ๋”ฐ๋ผ ๊ฐ’์„ ๋‹ค๋ฅด๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์น˜ํ™˜ํ•˜๊ณ ์ž ํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<!--  ๋นŒ๋“œ์‹œ ์†Œ์Šค์ฝ”๋“œ ์ธ์ฝ”๋”ฉ ํƒ€์ž… ์ง€์ • -->
	</properties>

์บก์ฒ˜

  • ๋นŒ๋“œ๋œ .jar ์—์„œ๋Š” ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์— ์ƒ์„ฑํ•œ webapp์„ ํฌํ•จํ•˜์ง€ ์•Š์€์ฑ„๋กœ ๋นŒ๋“œ๋˜์ง€ ์•Š๋Š”๋‹ค.
  1. new โžก๏ธ ๐Ÿ“ SourceFolder ("/resources”)
  2. ๐Ÿ“ webapp โžก๏ธ ๐Ÿ“ SourceFolder ("/resources”)
  3. ๐Ÿ“ ROOT project โžก๏ธ ๐Ÿ”ง Properties โžก๏ธ Java Build Path์˜ include ํ™•์ธ
  4. ๐Ÿ“„ pom.xml์— <resources>์ถ”๊ฐ€
  • โœ”๏ธ (Optional) DOCUMENT_ROOT path๋ฅผ ์ ˆ๋Œ€๊ฒฝ๋กœ๋กœ ๋ฐ”๊พธ์–ด ์ฃผ๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์•ผํ•œ๋‹ค.

  • โ—๏ธ ํด๋ž˜์Šค ๋กœ๋”ฉ์‹œ ์‹คํ–‰๋˜๋Š” static{}๋ฅผ ๋งŒ๋“ค์–ด ์ ˆ๋Œ€๊ฒฝ๋กœ๋ฅผ ๋ฐ”๊ฟ”์ฃผ์ž

    static {
        // this๊ฐ€ ๋กœ๋”ฉ๋์„๋•Œ ์‹คํ–‰๋˜๋Š” ๋ถ€๋ถ„
        try {
            documentRoot = new File(RequestHandler.class.
                    getProtectionDomain().
                    getCodeSource().
                    getLocation().
                    toURI()).
                    getPath();
    
            documentRoot += "/webapp";
    
            System.out.println("---->" + documentRoot);
    
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }