åå€æŽåŸãã©ã®ããã«å®è¡ããŠãã§ãã¯ããŸããïŒ åã¢ããªã±ãŒã·ã§ã³ãšã³ã³ããã®åèµ·åã«ã¯ã©ããããæéãããããŸããïŒ
ããŸããŸãªãªãã·ã§ã³ãèŠãæ©äŒããããŸãããWARãã¡ã€ã«ã®å®å šãªåæ§ç¯ãããMyEclipseãWTPããµãŒãã¬ããã³ã³ããŒã¿ãŒã®ãã³ãã¯ã¿ãŒããªã©ã®IDEã®ãã©ã°ã€ã³ã®äœ¿çšãŸã§ã ãããã®ããã€ãã«ã¯æãããªæ¬ é¥ããããä»ã®ãã®ã¯éåžžã«ããŸãæ©èœããŸã-ãããããã£ãšç°¡åãªæ¹æ³ããããŸãïŒ
ã©ã³ãã£ãŒ
ãã®éçºæ¹æ³ã«ãããæå°éã®åãããã€ã¡ã³ãæé㧠ãã§ããã ãç°¡åãã€æè»ã«ã¢ããªã±ãŒã·ã§ã³ãæ§æã§ããŸã ã mainã¡ãœããã䜿çšããŠ1ã€ã®åçŽãªJavaã¯ã©ã¹ãèšè¿°ããã ãã§ãå¿ èŠãªã¢ããªã±ãŒã·ã§ã³ïŒããããåã蟌ã¿ã¢ãŒã ïŒã§JettyãµãŒããŒãããã«èµ·åããŸãã
ããããªã¹ãã©ã³ãã£ãŒã¯æ¬¡ã®ããã«ãªããŸãã
import org.mortbay.jetty.*; import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.webapp.WebAppContext; public class Launcher { public static void main(String[] args) throws Exception { Server server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(8080); server.addConnector(connector); WebAppContext root = new WebAppContext("root/src/main/webapp", "/"); WebAppContext reports = new WebAppContext("reports/src/main/webapp", "/reports"); WebAppContext petclinic = new WebAppContext("petclinic/src/main/webapp", "/petclinic"); server.setHandlers(new Handler[]{root, reports, petclinic}); server.start(); } }
ãã®ã³ãŒãã¯ãããŒã8080ã§ãªãã¹ã³ãããµãŒããŒïŒãµãŒãã¬ããã³ã³ããïŒãèµ·åãã3ã€ã®Webã¢ããªã±ãŒã·ã§ã³ã䜿çšããŸããã³ãŒãã¯ãããžã§ã¯ããã©ã«ã ïŒ
root/src/main/webapp
ã
reports/src/main/webapp
ããã³
petclinic/src/main/webapp
ïŒãã€ãŸãããã¡ã€ã«ãžã®å€æŽã¯ããã«åæ ããã äœããåæ§ç¯ããŠåã€ã³ã¹ããŒã«ããå¿ èŠã¯ãããŸããã
æ°ããã¡ãœãããè¿œå ããå Žåãåèµ·åããå¿ èŠãããããšã¯æããã§ããããã®å Žåãåèµ·åã¯æåéã1ç§ä»¥å ã«ã§ããã ãæ©ãè¡ãããŸãïŒãã¡ãããã¢ããªã±ãŒã·ã§ã³ãèµ·åæã«è€éãªããšãããªãå ŽåïŒã ããã«JRebelããã蟌ãã å Žåãéåžžã¯ãã§ã³ã¬ãŒãã«ãªããŸãã
ãããããªãã¯ã§ãã
å®çšŒåç°å¢ã§ã¯ãJettyã§ã¯ãªãTomcatãJBossããŸãã¯WebLogicãªã©ã䜿çšããŠããŸãã åé¡ã§ã¯ãããŸãããé床ãå®å®æ§ãªã©ã®éçºã«ã€ããŠè©±ããŸãã éèŠã§ã¯ãããŸããããã»ããã¢ããã®å®¹æããèµ·åã®é床ãåå±éãéèŠã§ãã ãããŠãããã§åã蟌ã¿Jettyã¯å»åž«ã泚æãããã®ã§ãã
ãæ°ã«å ¥ãã®IDEãããã®ã¡ã€ã³ã¯ã©ã¹ãå®è¡ãããããã°ããã¹ããåèµ·åããã ãã§ãã ãã©ã°ã€ã³ã¯äžèŠã§ãæ§æãã¡ã€ã«ãæ¢ãå¿ èŠããXMLãæãäžããå¿ èŠããããŸããã ããªãã®æå ã§ãã¹ãŠã®èšå®ã ããã人çã§ãïŒ
æå°æ§æã§èµ·åããã«ã¯ã servlet-api.jar ã jetty.jar ã jetty-util.jarã® 3ã€ã®jarãã¡ã€ã«ã ãã§ååã§ãã
[UPD] kblcukã瀺åããããã«ãæå®ãããã¹ã¿ãŒãã¢ããã³ãŒãã¯Jetty 6ã§ã®ã¿æ©èœããŸããJettyã®7çªç®ã®ããŒãžã§ã³ãããããã±ãŒãžãšã¯ã©ã¹ã®ååãorg.mortbay.jettyããå€æŽãããŸãããã€ã³ããŒãã
ãã¥ãŒãã³ã°
ãããžã§ã¯ãã«ãã£ãŠã¯äŸ¿å©ãªè¿œå æ©èœãããã€ãæ€èšããŠãã ããã
ã¯ã©ã¹ããŒããŒ
äžèšã®ã³ãŒãã¯ããã¹ãŠã®Webã¢ããªã±ãŒã·ã§ã³ã®ã¯ã©ã¹ãšäŸåé¢ä¿ã1ã€ã®ããŒããŒïŒClassLoaderïŒã«ããŒãããŸãã äœããã®çç±ã§ãWebã¢ããªã±ãŒã·ã§ã³ã«ç°ãªãã¯ã©ã¹ãšäŸåé¢ä¿ïŒjarïŒã®ã»ãããããããšãéèŠãªå Žåãããã¯å°ããªã³ãŒããè¿œå ããããšã§ãå®è¡ã§ããŸãã
WebAppContext petclinic = new WebAppContext("petclinic/src/main/webapp", "/petclinic"); WebAppClassLoader classLoader = new WebAppClassLoader(petclinic); classLoader.addClassPath("petclinic-core/target/classes"); classLoader.addClassPath("petclinic-services/target/classes"); petclinic.setClassLoader(classLoader);
ç§èªèº«ã¯ãããããã®ïŒç«¶åããïŒäŸåé¢ä¿ãæã€å€ãã®Webã¢ããªã±ãŒã·ã§ã³ãäžåºŠã«å®è¡ããå¿ èŠããããšãã«ããããç©æ¥µçã«äœ¿çšããŸããã éåžžã«ã·ã³ãã«ã§éåžžã«äŸ¿å©ã§ãã
JSP
æã®äººã¯ãå¿ããããªãæ代ã«ãJSPã®ãããªãã®ãHTMLã®åœ¢æã«ãã°ãã°äœ¿çšãããããšãèŠããŠããŸãã ãããžã§ã¯ãã§JSPã䜿çšããå Žåã¯ãããã«ããã€ãã®äŸåé¢ä¿ãè¿œå ããå¿ èŠããããŸãïŒ eclipse-jdtcore.jar ã jsp-api-2.1- glassfish.jar ã jsp-2.1-glassfish.jar
JDBCãªãœãŒã¹ã®æ§æ
ããããããç°¡åãªè§£æ±ºçããããããããŸãããããã®ãªãã·ã§ã³ã¯ç§ã®ããã«åããïŒ
import import javax.naming.InitialContext; import com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean; static void setupDataSources() { System.setProperty("java.naming.factory.initial", "org.mortbay.naming.InitialContextFactory"); AtomikosNonXADataSourceBean dataSource = new AtomikosNonXADataSourceBean(); dataSource.setUniqueResourceName("jdbc/portal"); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/mydb"); dataSource.setUser("myusername"); dataSource.setPassword("mypassword"); dataSource.setMaxPoolSize(10); new InitialContext().createSubcontext("jdbc").bind("portal", dataSource); }
ãããè¡ãã«ã¯ã transactions.jar ã jetty-naming.jar ã transactions-api.jar ã transactions-jta.jar ã transactions-jdbc.jar ã atomikos-util.jarãè¿œå ããå¿ èŠããããŸã ã
ããå°ãèªååããããšã¯å¯èœã§ããïŒ
ã§ããŸãã ãã ããå¿ èŠãªå Žåã®ã¿ã
ããŒã¿ããŒã¹ã®ã¢ãã¬ã¹ãŸãã¯ãã¹ã¯ãŒããé »ç¹ã«å€æŽãããå Žåã¯ãããã€ãã®ãã¡ã€ã«ããããããèªã¿åãããšãã§ããŸãã å¯èœã§ãã ããããããã ãã®äŸ¡å€ã¯ãããŸããïŒ äž»ãªããšã¯ããã¹ãŠã®èšå®ã1ã€ã®ãã¡ã€ã«ã«éäžããŠããããšã§ãããããã¯ã©ã®ãããªçš®é¡ã®ãã¡ã€ã«ïŒJavaã¯ã©ã¹ãŸãã¯* .propertiesïŒãªã®ã§ããããïŒ
Webã¢ããªã±ãŒã·ã§ã³ã®ãªã¹ãã絶ããå€åããŠããå Žåã¯ãEclipseãŸãã¯IDEAã®ãã©ã°ã€ã³ãäœæããŠãçŸåšEclipseã«ãããã¹ãŠã®ãããžã§ã¯ãã§Jettyãå®è¡ããããšããå§ãããŸãã ãã®ãããªãã©ã°ã€ã³ã®1ã€ãããã§èª¬æããŸã ãweb.xmlãã¡ã€ã«ãæã€ãã¹ãŠã®ãããžã§ã¯ããèŠã€ããæ®ãã®ãããžã§ã¯ããã¯ã©ã¹ãã¹ã§ãããã«è¿œå ããŸãã
çæ
客芳æ§ã®ããã«ããã®ã¢ãããŒãã«æœãèœãšãç©Žã«ååãä»ããããšããŸãã
- ïŒæ³åäžã®ãã€ãã¹ïŒ Jettyã³ã³ããã¯ãTomcatãJBossãResinãªã©ã«æ¯ã¹ãŠããã©ãŒãã³ã¹ãå£ããŸãã
ãã³ã»ã³ã¹ã ç§ãã¡ã¯ä»ãéçºã«ã€ããŠè©±ããŠããŸã-ããã©ãŒãã³ã¹ã¯ããã§ã¯å®å šã«ç¡é¢ä¿ã§ãã
ã¡ãªã¿ã«ãããã¯ãããå£ã£ãŠãããã©ããã®å¥ã®è³ªåã§ãã
- ïŒæ³åäžã®ãã€ãã¹ïŒ Jettyã³ã³ããã¯äžå®å®ã§ãã/æã
ã¯ã©ãã·ã¥ãã/ã¡ã¢ãªãªãŒã¯ãå«ãã
ãã³ã»ã³ã¹ã åã®æ®µèœãåç §ããŠãã ããã
- ã¢ããªã±ãŒã·ã§ã³ãç¹å®ã®ã³ã³ããïŒç¹ã«WebLogicãŸãã¯Oracle ASïŒã®ç¹å®ã®æ©èœã䜿çšããŠããå Žåãåœç¶ãJettyã§ã¯æ©èœããŸããã
ããããäœãããããšã¯ãããŸããã ã¢ããªã±ãŒã·ã§ã³ãã³ã³ããã«äŸåããªãããã«ããã®ãããªæ©èœã䜿çšããªãããšããå§ãããŸãã
- å Žåã«ãã£ãŠã¯ãã¢ããªã±ãŒã·ã§ã³ãåã蟌ã¿Jettyã¢ãŒãã§ã³ã³ãã¥ãŒã¿ãŒäžã§æ£åžžã«å®è¡ãããŸãããæŠäºã§çµã¿ç«ãŠãããŠå¥ã®ãµãŒããŒã«ã€ã³ã¹ããŒã«ããããšã¯ã©ãã·ã¥ããŸãã
ããã¯ãŸãã§ãããèµ·ãããŸãã ç¹ã«ãã¯ã©ã¹ããŒããŒãŸãã¯jarããŒãžã§ã³ãåå ã§ãšã©ãŒãçºçããå ŽåããããŸãã
代æ¿æ¡
èå³ãåŒãããã«ã䞻芳çãªè©äŸ¡ã§Java Webã¢ããªã±ãŒã·ã§ã³ãéçºããå¥ã®æ¹æ³ããªã¹ãããŸãã
- WARãã¡ã€ã«ã®åæ§ç¯ãšTomcat / webappsãžã®ã³ããŒãå®äºããŸãã
æãä¿¡é Œæ§ãé«ãæãé ããœãªã¥ãŒã·ã§ã³ã CSSãå€æŽããããã³ã«1ã15ååŸ æ©ããããšãæ³åããŠãã ããã ããããããããšãã
å°ãªãïŒã²ã©ãé·ãã
ãã€ãã¹ïŒãããã°ãåå¥ã«æ§æããå¿ èŠããããŸãïŒãªã¢ãŒããããã°ïŒã ããã»ã©é£ãããªããããããŸããããããã§ãäœåãªåŽåãå¿ èŠã§ãã - Myclipse
ææã®EclipseããŒã¹ã®IDEã ãããžã§ã¯ããã³ã³ãã€ã«ãããšããã¹ãŠã®ãªãœãŒã¹ãå¥ã®ãã©ã«ããŒã«ã³ããŒãããŸã-ããã¯ç§ã«ãšã£ãŠéåžžã«é·ãéåããŸããã ãŸããèšå®ã®ãã©ãã«ã«ããäžå¿«ãªæãåºããããŸãã - Eclipse WTP ïŒWeb Tools PlatformïŒã¯ç¡æã§ãããEclipseçšã®éããã©ã°ã€ã³ã§ã
äœåºŠãè©ŠããŠã¿ãŸããããå¿ èŠãªæ¹æ³ã§æ§æã§ããŸããã§ããã
ããã«ãããã€ãã®ç°ãªãã³ã³ããïŒTomcatãJBossãªã©ïŒã§åäœã§ããŸãã
[UPD]ãããã ãã㧠Akvelã¯ã圌ãEclipse WTPãç°¡åã«äœ¿çšããæ¹æ³ã«ã€ããŠè©±ããŠããŸãã
- ã¢ããªã±ãŒã·ã§ã³ãµãŒããŒã®çµ±å
Eclipse WTPã¢ããã°ãIntellijIDEAã®ææçã§ã®ã¿å©çšå¯èœã§ãã
ãã€ãã¹ïŒææã - ãžã¥ã¬ãã«
JRebelã§ã¯ãã¡ã€ã³ã¿ã¹ã¯ã«å ããŠããããžã§ã¯ãããçŽæ¥ClassPathã¢ããªã±ãŒã·ã§ã³ãæ§æã§ããŸãã
ãã€ãã¹ïŒJRebelãæ¯æã£ãã
å ããŠãéçšäž»ããããæ±ããŠããå ŽåãJRebelã¯éçºè ã®äœæ¥ãå€§å¹ ã«ç°¡çŽ åããã¹ããŒãã¢ããã§ããŸãã - ãã¬ã€ïŒ æ çµã¿
ãããžã§ã¯ãããçŽæ¥ã¢ããªã±ãŒã·ã§ã³ãå®è¡ããå€æŽãããã³ãŒãããã®å Žã§ãªãŒããŒããŒãã§ããŸãã ãšãŠãå¿«é©ã§ãã
ãã€ãã¹ïŒç¬èªã®ç¹æ§ãšå¶éããã1ã€ã®ãã¬ãŒã ã¯ãŒã¯ã«å¶éãããŸãã - æ¡æ©èµ°è¡
ãããžã§ã¯ãããçŽæ¥ã¢ããªã±ãŒã·ã§ã³ã§Jettyãå®è¡ã§ããããã«ããEclipseçšã®ãã©ã°ã€ã³ã å®éã圌ã¯ãã®èšäºã§èª¬æãããã®ãšãŸã£ããåãããšãããŠããŸãã
ããã«ãå¿ èŠãªãã¹ãŠã®jarãå«ãŸããŠããããããã©ã°ã€ã³èªäœãé€ããŠä»ã®ãã®ãããŠã³ããŒãããå¿ èŠã¯ãããŸããã
ãã€ãã¹ïŒå®è¡ã§ãããããžã§ã¯ãã¯1ã€ã ãã§ãã
ãã€ãã¹ïŒããŒã¿ããŒã¹ãžã®æ¥ç¶ãæ§æããæ¹æ³ãç¥ããŸããã ãšã«ããæã§ãããããªããã°ãªããŸããã - [UPD] Jetty Mavenãã©ã°ã€ã³
1nd1goã瀺åããŠããããã«ããããžã§ã¯ãã§Mavenã䜿çšããŠããå Žåãã³ãã³ããmvn jetty:run
ãã§Webã¢ããªã±ãŒã·ã§ã³ãå®è¡ã§ããŸãã
ããã«ãIDEã§Mavenãã©ã°ã€ã³ã䜿çšããå Žåããã®ã³ãã³ããIDEããçŽæ¥å®è¡ã§ããŸãã åæã«ãã£ããŒã¹ã§ããŸã jettyãã©ã°ã€ã³ã¯ãMavenãšåãããã»ã¹ã§å®è¡ãããŸãã
å°ãªãïŒãã«ãã·ã¹ãã ïŒmavenïŒãšIDEã«çžãããŠããŸãã - [UPD] Jetty Gradleãã©ã°ã€ã³
ãããžã§ã¯ãã§Gradleã䜿çšããŠããå Žåããgradle jettyRun
ãgradle jettyRun
䜿çšããŠWebã¢ããªã±ãŒã·ã§ã³ãå®è¡ã§ããŸãã
ããã«ããã®ã³ãã³ãã¯ïŒãã©ã°ã€ã³ããªããŠãïŒIDEããçŽæ¥å®è¡ãããããããããã°ããããšãã§ããŸãã
LessïŒãã«ãã·ã¹ãã ïŒgradleïŒã«çžãããŠããŸãã - [UPD] Sysdeo Eclipse Tomcat Launcherãã©ã°ã€ã³
helions8ã瀺åããããã«ãEclipseçšã®åªããSysdeo Tomcatã©ã³ãã£ãŒãã©ã°ã€ã³ããããŸããããã«ãããããããšãããžã§ã¯ãã®ã³ã³ããã¹ããçµã¿åãããããšãã§ããŸãããã®ãããwarãã¡ã€ã«ãåéããŠã³ã³ãããŒã«æ·»ä»ããå¿ èŠã¯ãããŸãããcssãhtmlãããã³ãã®ä»ã®jsã¯ããã«ãããã«ãªãã€ã¬ã¯ããããŸãã ã»ãšãã©ã®å Žåãããããªãã¬ãŒã¹ãæ©èœããŸãã åºæ¬çã«ããã®ãã©ã°ã€ã³ã¯ã©ã³ãã£ãŒãšåãããšãè¡ããŸãã
LessïŒEclipseã«æ¥ç¶ãããŠããŸãã
ãã€ãã¹ïŒå€§éšããå¿ èŠã§ãã Tomcatãèªåã§ããŠã³ããŒãããæ°ãããtomcatãããžã§ã¯ãããäœæããå¿ èŠããããŸããããã¯äžè¬çã«ã¯ããªãåªããããŒã«ã§ãããèµ·åã¯ç°¡åã§ãã - [UPD] SpringãœãŒã¹ããŒã«ã¹ã€ãŒã
alexeygrigorevã瀺åããããã«ãEclipseã«ã¯ããã¡ã€ã«ãä¿åãããšãã«åãããã€ã§ããçµã¿èŸŒã¿ã®ãæŽç·Žãããtomcatããæã€SpringãœãŒã¹ããŒã«ã¹ã€ãŒããã©ã°ã€ã³ããããŸã
å°ãªãïŒEclipseãšSTSã«æ¥ç¶ããŠããŸãã
çµã¿èŸŒã¿ã¢ãŒãã§ã¯ãJettyã ãã§ãªãTomcat ã Glassfishãªã©ãèµ·åã§ããããšãè¿œå ããå¿ èŠããããŸã ãç¹å®ã®ã³ã³ããã¯éèŠã§ã¯ãªããååã¯éèŠã§ãïŒé·ãåçµã¿ç«ãŠãã€ã³ã¹ããŒã«ã解åãæ§æã¯ãããŸããã ãã¹ãŠã¯1ã€ã®ã¯ã©ã¹ããè¿ éãã€ç°¡åã«éå§ãããŸãã
ç§èªèº«ã¯æ°å¹Žåãããã®æ¹æ³ã§Webã¢ããªã±ãŒã·ã§ã³ãéçºããŠãããä»ã®äººã«ãã¢ããã€ã¹ããŠããŸãã ãã®ãããçµã¿ç«ãŠãèšçœ®ã«äŒŽãhéšã«è²»ããæéãå°ãªããªããå®éã®éçºã«éäžã§ããŸãã
èµ·åããŠãã ããïŒ