{"id":338,"date":"2009-12-17T16:15:26","date_gmt":"2009-12-17T16:15:26","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=338"},"modified":"2010-02-26T21:05:28","modified_gmt":"2010-02-26T21:05:28","slug":"using-eclipseeclipselinkjsfjpa-with-tomcat-6","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=338","title":{"rendered":"Using Eclipse\/JSF\/JPA with Tomcat 6"},"content":{"rendered":"<p>I&#8217;ve found that this is useful for prototyping\/mockups of apps that are targetted for GlassFish. It is possible to run JPA with Eclipselink outside an EJB\u00a0container, so a JSF\/JPA app can be run under Tomcat, resulting in less overhead and faster turnaround of changes. For a while I&#8217;ve\u00a0had to use a PC which is RAM limited, and so developing\/prototyping with Eclipse and Glassfish has been slow. Turning around deployments\/changes around takes time, and I&#8217;ve found the synchronisation between Eclipse and Glassfish to be a bit fussy &#8211; sometimes Eclipse misunderstands the state of Glassfish, needing a Glassfish restart which again takes valuable time.<\/p>\n<p>Note the following points on doing this:-<\/p>\n<p><strong>1\/<\/strong> My application stack looks similar to the &#8216;real&#8217; one, but my Service layer\/domain objects are just POJOs which are explicitly created or\u00a0injected via\u00a0<strong>faces_config.xml. <a title=\"http:\/\/www.oracle.com\/technology\/tech\/java\/newsletter\/articles\/jsf_pojo\/index.html\" href=\"http:\/\/www.oracle.com\/technology\/tech\/java\/newsletter\/articles\/jsf_pojo\/index.html\">This Oracle Example<\/a><\/strong><a title=\"http:\/\/www.oracle.com\/technology\/tech\/java\/newsletter\/articles\/jsf_pojo\/index.html\" href=\"http:\/\/www.oracle.com\/technology\/tech\/java\/newsletter\/articles\/jsf_pojo\/index.html\"> <\/a>details the various IOC features of the JSF. managed bean facility.<\/p>\n<p><strong>2\/<\/strong> Persistence.xml needs setting up differently to run JPA outside the container. I have found it\u00a0easiest to specify the database connection explicitly, rather than using a data source. In Eclipse, you can use the <strong>persistence.xml<\/strong> editor to populate the connection properties directly from the one Eclipse uses for its entity validation. Whilst you can do JNDI lookups of a data source stored in Tomcat, the naming context used is different, as it makes use of the Enterprise Naming Context (ENC), i.e. &#8220;java:comp\/env&#8221;. <a title=\"http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/jndi-resources-howto.html\" href=\"http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/jndi-resources-howto.html\"><strong>This<\/strong> <\/a>example details how to do it if you want to go that way. A sample <strong>persistence.xml<\/strong> follows (with entries commented out where they have been replaced for use with Tomcat)\u00a0:-\u00a0<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;persistence version=\"1.0\" xmlns=\"<a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\">http:\/\/java.sun.com\/xml\/ns\/persistence<\/a>\"\r\n\u00a0xmlns:xsi=\"<a href=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\">http:\/\/www.w3.org\/2001\/XMLSchema-instance<\/a>\"\r\n\u00a0xsi:schemaLocation=\"<a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\">http:\/\/java.sun.com\/xml\/ns\/persistence<\/a>\r\n\u00a0<a href=\"http:\/\/java.sun.com\/xml\/ns\/persistence\/persistence_1_0.xsd\">http:\/\/java.sun.com\/xml\/ns\/persistence\/persistence_1_0.xsd<\/a>\"&gt;\r\n\r\n\u00a0&lt;!--&lt;persistence-unit name=\"SentryPrototype\" transaction-type=\"JTA\"&gt;--&gt;\r\n\u00a0&lt;persistence-unit name=\"SentryPrototype\" transaction-type=\"RESOURCE_LOCAL\"&gt;\r\n\r\n\u00a0\u00a0 &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;\/provider&gt;\r\n\r\n\u00a0\u00a0 &lt;!--&lt;jta-data-source&gt;jdbc\/JPATestPool&lt;\/jta-data-source&gt;--&gt;\r\n\r\n\u00a0\u00a0 &lt;class&gt;uk.co.salientsoft.jpatest.domain.UserInfo&lt;\/class&gt;\r\n\u00a0\u00a0 &lt;properties&gt;\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.logging.level\" value=\"INFO\" \/&gt;\r\n\r\n\u00a0\u00a0\u00a0 &lt;!-- &lt;property name=\"eclipselink.target-server\" value=\"SunAS9\" \/&gt;--&gt;\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.target-server\" value=\"None\" \/&gt;\r\n\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.session-name\" value=\"SentryPrototypeSession\" \/&gt;\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.target-database\" value=\"Oracle\" \/&gt;\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.ddl-generation.output-mode\" value=\"database\" \/&gt;\r\n\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.jdbc.url\" value=\"jdbc:oracle:thin:@localhost:1521:xe\"\/&gt;\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.jdbc.user\" value=\"sentry\"\/&gt;\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.jdbc.password\" value=\"sentry\"\/&gt;\r\n\u00a0\u00a0\u00a0 &lt;property name=\"eclipselink.jdbc.driver\" value=\"oracle.jdbc.OracleDriver\"\/&gt;\r\n\r\n\u00a0\u00a0 &lt;\/properties&gt;\r\n\u00a0 &lt;\/persistence-unit&gt;\r\n&lt;\/persistence&gt;<\/pre>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>3\/\u00a0<\/strong>Ref <strong><a title=\"http:\/\/wiki.eclipse.org\/EclipseLink\/Examples\/JPA\/Tomcat_Web_Tutorial\" href=\"http:\/\/wiki.eclipse.org\/EclipseLink\/Examples\/JPA\/Tomcat_Web_Tutorial\">this eclipse tutorial<\/a>\u00a0:-<br \/>\n<\/strong>Tomcat does not have an EJB container so you must add EJB 3.0\/JPA 1.0 capability for EclipseLink JPA by placing the specification persistence.jar into the container lib directory <em>$TOMCAT_HOME\/lib.<br \/>\n<\/em>It is recommended to put persistence_1_0.xsd there as well.\u00a0 It is not recommended that the WAR include its own version of persistence.jar. Your eclipse project should reference but not include this jar and xsd.<\/p>\n<p>The eclipselink.jar should be placed off of the container lib directory <em>$TOMCAT_HOME\/lib.<br \/>\n<\/em>Since Tomcat does not include an EJB container, you may put eclipselink.jar in the web applications&#8217;s lib directory or higher up in the classloader by putting it off of Tomcats&#8217; lib directory, where all web applications can access it.<br \/>\nDo not split the eclipselink.jar from the javax.persistence jar &#8211; keep them together &#8211; preferably in <em>$TOMCAT_HOME\/lib<\/em><\/p>\n<p><strong>\u00a04\/<\/strong> Tomcat has its own dependencies on the Expression Language (EL) web libraries. These should be removed from WEB_INF\/lib when deploying to Tomcat as pointed out <strong><a title=\"http:\/\/lists.onehippo.com\/pipermail\/hippocms-dev\/2008-May\/004668.html\" href=\"http:\/\/lists.onehippo.com\/pipermail\/hippocms-dev\/2008-May\/004668.html\">here<\/a><\/strong>. (If you do not do this, the application will crash with duplicate class loading exceptions.) This may be done in eclipse on the <strong>Java Server Faces facet page<\/strong>\u00a0&#8211; open the project properties for the project, and select <strong>Java Server Faces<\/strong> under <strong>Project Facets.<\/strong> Untick the entry for <strong>Standardized EL Library v1.0.<\/strong><\/p>\n<p><script type=\"text\/javascript\">\/\/ <![CDATA[\n       img(\"2009\/12\/17\/jpatomcat\/jsfproperties.png\",\"Java Server Faces Facet Page\",\"screen\");\n\/\/ ]]><\/script><\/p>\n<p>Then save the changes and redeploy the application.<\/p>\n<p>For more information, <a title=\"http:\/\/wiki.eclipse.org\/EclipseLink\/Examples\/JPA\/Tomcat_Web_Tutorial\" href=\"http:\/\/wiki.eclipse.org\/EclipseLink\/Examples\/JPA\/Tomcat_Web_Tutorial\"><strong>the eclipse tutorial referenced in 3\/<\/strong>\u00a0<\/a>goes into greater depth on the subject. You can also find a list of the available eclipse JPA tutorials <strong><a title=\"http:\/\/salientsoft.co.uk\/?p=77\" href=\"http:\/\/salientsoft.co.uk\/?p=77\">here<\/a>.<\/strong><\/p>\n<p><strong>5\/ <\/strong>When running xxxxxx<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve found that this is useful for prototyping\/mockups of apps that are targetted for GlassFish. It is possible to run JPA with Eclipselink outside an EJB\u00a0container, so a JSF\/JPA app can be run under Tomcat, resulting in less overhead and faster turnaround of changes. For a while I&#8217;ve\u00a0had to use a PC which is RAM [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[9,35,182,184,39,37,15],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/338"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=338"}],"version-history":[{"count":31,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":345,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions\/345"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}