Java ã§ã® web ã¢ããªã±ã¼ã·ã§ã³éçºæã®éçºç°å¢ã¡ã¢ #1
æè¿ Java 㧠web ã¢ããªã±ã¼ã·ã§ã³ãéçºãããã¨æã£ã¦ãã¢ããªã±ã¼ã·ã§ã³æ§æããéçºç°å¢å¨ãããæ©ãã ããã¦ããã®ã ããã©ãããç¨åº¦è¯ããããªæ§æã«è½ã¡çãã¤ã¤ããã®ã§ç¾ç¶ãã¡ã¢ãã¦ããã
ã¢ããªã±ã¼ã·ã§ã³æ§æ
ã¨ãããã HTTP å¨ã㯠JAX-RS ã«ä»»ããã®ãè¯ãããã JAX-RS å®è£ ã¨ãã¦ã¯ Jersey ãé¸æã JBoss RESTEasy ã¨ãã試ãã¦ã¿ããã©ãJAX-RS ã®åç §å®è£ ã¨ãããã¨ããã£ã¦ Jersey ã¯çãå°ãªãã¦ä½¿ããããã®ããªã¼ã¨æã£ããããã Web ä¸ã®æ å ±ãå¤ãããªæ°ãããã
- JAX-RS 2.0
- Jersey 2.4
- Servlet ã³ã³ããå ã§åãããã¨ãæ³å®
ãã«ããã¼ã«ã¨ãã¦ã¯ Gradle ãé¸æã IDE ã¨ã®é£æºãèãã㨠Maven ã®æ¹ãæå©ããªã¼ã¨ãæã£ããã©ãå®é Eclipse 㨠NetBeans ã§è©¦ããã¨ãã大差ãªããããªæãã ã£ãã®ã§ã
ããã辺ã®è©±ã¯ä¸ã®è¨äºã«æ¸ããã
DB å¨ããã©ãããã®ãã¯ã¾ã æ©ã¿ä¸ã§ãä»ã®ã¨ãã㯠JDBC ã使ã£ã¦ SQL ãã¹ãæ¸ããã¦ãã ä½ãããããã¡ãã£ã¨ä¸ã«ãã¶ãã¦ä½¿ãããã¨ã¯æã£ã¦ããã©ãã©ãããããã¯ã¾ã ããã£ã¦ãªãã Hibernate ã軽ã試ãã¦ã¿ã¦ãæªãã¯ãªããã©ä»ãã使ãããã£ã¦æãã§ã¯ãªãã£ãããããã¡ãã£ã¨ãããã試ãã¦ã¿ããã¨ããã
ã¢ããªã±ã¼ã·ã§ã³æ§æã«é¢ããåèè³æ
ã¢ããªã±ã¼ã·ã§ã³æ§æã«é¢ãã¦ã¯æ¬¡ã® Gist ãåèã«ãªãã
éçºç°å¢å¨ã
ã§ãIDE 㯠EclipseãNetBeansãIntelliJ ãããã試ãã¦ã¿ãã NetBeans ã¯ä»ååãã¦è§¦ã£ã¦ã¿ã¦ãããã©ã«ãã®ç¶æ 㧠Java EE å¨ããæ±ãã®ã¯ããªãããããããã«æããã ãã ãMaven ã Gradle ã使ã£ã¦ããããã¸ã§ã¯ããã¤ã³ãã¼ããããã㧠web ã¢ããªã±ã¼ã·ã§ã³ç¨ã®ããã¸ã§ã¯ãã¨ãã¦æ±ãããæ¹æ³ãè¯ãããããªãã£ãã®ã§æ念ã IntelliJ ã«é¢ãã¦ã¯ Android Studio ã¨ãã¦è§¦ã£ããã¨ããããã¨åææã« Java ãæ¸ãã®ã«ã¡ãã£ã¨ä½¿ã£ããããã¦ã¿ããã©ãããã¾ãèªåã«ã¯åããªãæããããã ã§ãEclipseã Gradle ã使ã£ãããã¸ã§ã¯ãã®ã¤ã³ãã¼ããã§ãããã©ããä¸å®ã ã£ããã©ãGradle ãã©ã°ã¤ã³ã使ã£ã¦ã¤ã³ãã¼ãããä¸ã§ãããã¸ã§ã¯ãã web ã¢ããªã±ã¼ã·ã§ã³ç¨ã«ãããã¨ããæãã®ãã¨ãã§ããã
ã¾ã IDE ä¾åæ§ã¯å°ãªãããããã©ãã§ãè¯ãã£ãã®ã ãã©ãæ®éã«ä½¿ãåã«å°ããªãã®ã Eclipse ãããªãã£ãã®ã§ Eclipse ã¨ããã
ãã¨ãéçºç¨ãµã¼ãã¼ã Eclipse ã¨é£æºããã¦åããããã« run-jetty-run ãã©ã°ã¤ã³ã使ç¨ãããã¨ã«ããã éçºç¨ãµã¼ãã¼ã¨ãã¦ã¯ Tomcat ã¨ã GlassFish ãããã試ãã¦ã¿ããã©ããã¯ãèµ·åã®éããèãã㨠Jetty ãè¯ãããã ãã¾ã® Run-Jetty-Run ã® nightly ãã¼ã¸ã§ã³ã 㨠Jetty 9 ã«ã対å¿ãã¦ããã®ã§ãnightly ãã¼ã¸ã§ã³ã使ã£ã¦ Jetty 9 ã§åããã¦ãã
Gradle ã®ãã«ãããã¸ã§ã¯ãæ§æãã¡ããã¨ã¤ã³ãã¼ãã§ããããEclipse ã§ä»ã®ã¨ããã¯ä¸æºã¯ãªãã
ç´°ãããã¦ãã¦çãªãã®
- ããã¸ã§ã¯ãã¤ã³ãã¼ã㯠ãGradle Projectã ã¨ãã¦è¡ãã
- ã¤ã³ãã¼ãããããã¸ã§ã¯ãã web ã¢ããªã±ã¼ã·ã§ã³ç¨ã«ããããã«ãããã¸ã§ã¯ããå³ã¯ãªãã¯ã㦠ãConfigureã ã® ãConvert to Faceted Form...ã ãé¸æããéããã ãProject Facetsã ãã ãJAX-RS (REST Web Service)ã ãé¸ã¶ã
- ããããè¦åãåºããããã¨æããã©ãã¡ãã»ã¼ã¸ã«å¾ã£ã¦è¨å®ãå¤æ´ã
- ã¨ããæãã§ã¤ã³ãã¼ãã¯ã§ããã¯ãã
- ä¾åé¢ä¿ç®¡çã¯åºæ¬çã« Gradle ãã©ã°ã¤ã³ä»»ãã§ããæãã build.gradle ã«è¿½å ãããããã¸ã§ã¯ããå³ã¯ãªãã¯ã㦠ãGradleã ãã ãRefresh Dependenciesã ãããã
- ãã¾ã«ãããããªããã¨ããã£ããã©ãããã¸ã§ã¯ãå³ã¯ãªãã¯ã® ãGradleã ããä¾åé¢ä¿ç®¡çãä¸æ¦ããããã¨å度管çãããããã«ããã¨ããEclipse ã®åèµ·åããããç´ã£ãã
- Run-Jetty-Run ã®è¨å®ãå¤ããããã¡ã¤ã«ã®å¤æ´ãç£è¦ãã¦èªã¿è¾¼ã¿ãªããã¨ãããã¨ããã£ã¦ããããã©ããã¡ã®ç°å¢ã§ã¯ JDBC å¨ãã§ã¨ã©ã¼ãåºã¦ãã¾ã£ãã®ã§æåã§èµ·åãç´ãã¦ãã èµ·åæéçãã®ã§ç¹ã«ã¹ãã¬ã¹ã¯æãã¦ãªãã