<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title># kaleido</title>
	<atom:link href="http://www.kaleidofoundry.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kaleidofoundry.org/blog</link>
	<description>Around Java Technologies and KaleidoFoundry project</description>
	<lastBuildDate>Fri, 16 May 2014 18:59:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>GWT debugging, go further with jetty and maven</title>
		<link>http://www.kaleidofoundry.org/blog/2012/09/gwt-debug-jetty/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gwt-debug-jetty</link>
		<comments>http://www.kaleidofoundry.org/blog/2012/09/gwt-debug-jetty/#comments</comments>
		<pubDate>Fri, 21 Sep 2012 15:10:41 +0000</pubDate>
		<dc:creator>Jérôme RADUGET</dc:creator>
				<category><![CDATA[gwt]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://www.kaleidofoundry.org/blog/?p=91</guid>
		<description><![CDATA[Sometimes during the gwt debugging with Google plugin for Eclipse or with maven gwt plugin, you will need to access some jndi datasource or some environment parameters (like you can do it with tomcat). The default embedded  jetty do not provide &#8230; <a href="http://www.kaleidofoundry.org/blog/2012/09/gwt-debug-jetty/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes during the gwt debugging with <a href="https://developers.google.com/eclipse/">Google plugin for Eclipse</a> or with <a href="http://mojo.codehaus.org/gwt-maven-plugin" class="broken_link">maven gwt plugin</a>, you will need to access some jndi datasource or some environment parameters (like you can do it with tomcat). The default embedded  jetty do not provide this feature, and you will need a little hack to do this.</p>
<p>The following exemple define an environment variable and a datasource for tomcat and jetty:</p>
<p><strong>For tomcat :</strong> add to your &#8220;context.xml&#8221; :</p>
<pre class="brush: xml; gutter: true">&lt;Environment name=&quot;yourapp.basedir&quot;
	value=&quot;/path/to/project/target/app&quot;
	type=&quot;java.lang.String&quot; override=&quot;false&quot; /&gt;

&lt;Resource auth=&quot;Container&quot;
	driverClassName=&quot;org.apache.derby.jdbc.EmbeddedDriver&quot;
	name=&quot;jdbc/yourDatasource&quot; type=&quot;javax.sql.DataSource&quot;
	url=&quot;jdbc:derby:test;create=true&quot; username=&quot;APP&quot; password=&quot;APP&quot;
	maxActive=&quot;10&quot; maxIdle=&quot;4&quot;  /&gt;</pre>
<p><strong>For jetty embedded in gwt :</strong> create a new file jetty-web.xml, in your WEB-INF :</p>
<pre class="brush: xml; gutter: true">&lt;!DOCTYPE Configure PUBLIC &quot;-//Mort Bay Consulting//DTD Configure//EN&quot; &quot;http://jetty.mortbay.org/configure.dtd&quot;&gt;
&lt;Configure id=&quot;webAppCtx&quot; class=&quot;org.mortbay.jetty.webapp.WebAppContext&quot;&gt;
	&lt;New id=&quot;yourapp.basedir&quot; class=&quot;org.mortbay.jetty.plus.naming.EnvEntry&quot;&gt;
		&lt;Arg&gt;java:comp/env/yourapp.basedir&lt;/Arg&gt;
		&lt;Arg type=&quot;java.lang.String&quot;&gt;/path/to/project/target/app&lt;/Arg&gt;
		&lt;Arg type=&quot;boolean&quot;&gt;true&lt;/Arg&gt;
	&lt;/New&gt;
	&lt;New id=&quot;yourDatasource&quot; class=&quot;org.mortbay.jetty.plus.naming.Resource&quot;&gt;
		&lt;Arg&gt;java:comp/env/jdbc/yourDatasource&lt;/Arg&gt;
		&lt;Arg&gt;
			&lt;New class=&quot;org.apache.derby.jdbc.EmbeddedDataSource&quot;&gt;
				&lt;Set name=&quot;DatabaseName&quot;&gt;test&lt;/Set&gt;
				&lt;Set name=&quot;createDatabase&quot;&gt;create&lt;/Set&gt;
			&lt;/New&gt;
		&lt;/Arg&gt;
	&lt;/New&gt;
&lt;/Configure&gt;</pre>
<p>For the datasource, don&#8217;t forget to add to your web.xml :</p>
<pre class="brush: xml; gutter: true"> &lt;resource-ref&gt;
    &lt;description&gt;DB Connection&lt;/description&gt;
    &lt;res-ref-name&gt;jdbc/yourDatasource&lt;/res-ref-name&gt;
    &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
    &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;</pre>
<p>To access it from your java server class (ServletContextListener / Servlet &#8230;) :</p>
<pre class="brush: xml; gutter: true">try {
  Context initCtx = new InitialContext();

  // to access your datasource
  Datasource dataSource = (DataSource)context.lookup(&quot;java:comp/env/yourDatasource&quot;);
  // get a connection and use it ....

  // to access the environment entry list
  NamingEnumeration&lt;Binding&gt; bindingsEnum = initCtx.listBindings(&quot;java:comp/env&quot;);
  while (bindingsEnum.hasMore()) {
    Binding binding = bindingsEnum.next();
    System.out.printf(&quot;%s = %s\n&quot;, binding.getName(), binding.getObject().toString());
    // memorize this settings parameters somewhere ...
  }

 } catch (NamingException e) {
   // ... handle it
 }</pre>
<p><strong>Now, back to gwt, maven and eclipse :</strong></p>
<p>Add to your pom.xml  :</p>
<pre class="brush: xml; gutter: true">&lt;properties&gt;
  &lt;gwtVersion&gt;2.4.0&lt;/gwtVersion&gt;
  &lt;webappDirectory&gt;${project.build.directory}/${project.build.finalName}
  &lt;/webappDirectory&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
  &lt;!-- gwt core --&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
    &lt;artifactId&gt;gwt-servlet&lt;/artifactId&gt;
    &lt;version&gt;${gwtVersion}&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
    &lt;artifactId&gt;gwt-user&lt;/artifactId&gt;
    &lt;version&gt;${gwtVersion}&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;!-- needed by for jndi access (jetty embedded container) --&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
    &lt;artifactId&gt;jetty-plus&lt;/artifactId&gt;
    &lt;version&gt;6.1.11&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
    &lt;artifactId&gt;jetty-naming&lt;/artifactId&gt;
    &lt;version&gt;6.1.11&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;!-- only needed for datasource testing --&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
    &lt;artifactId&gt;derbyclient&lt;/artifactId&gt;
    &lt;version&gt;10.6.1.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
    &lt;artifactId&gt;derby&lt;/artifactId&gt;
    &lt;version&gt;10.6.1.0&lt;/version&gt;
  &lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;build&gt;
  &lt;finalName&gt;yourAppContext&lt;/finalName&gt;
  &lt;outputDirectory&gt;${webappDirectory}/WEB-INF/classes&lt;/outputDirectory&gt;

  &lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;gwt-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;${gwtVersion}&lt;/version&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;goals&gt;
          &lt;goal&gt;compile&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;configuration&gt;
      &lt;extraJvmArgs&gt;-Xmx512M -XX:MaxPermSize=196m -Xss1024k -Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory
      &lt;/extraJvmArgs&gt;
      &lt;runTarget&gt;YourApplication.html&lt;/runTarget&gt;
      &lt;hostedWebapp&gt;${webappDirectory}&lt;/hostedWebapp&gt;
    &lt;/configuration&gt;
  &lt;/plugin&gt;

  &lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
    &lt;version&gt;2.1.1&lt;/version&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;phase&gt;compile&lt;/phase&gt;
        &lt;goals&gt;
          &lt;goal&gt;exploded&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;configuration&gt;
      &lt;webappDirectory&gt;${webappDirectory}&lt;/webappDirectory&gt;
    &lt;/configuration&gt;
  &lt;/plugin&gt;
&lt;/build&gt;</pre>
<p>To explain, the two jetty dependencies are not included in the gwt-dev core (the debugging tool with the embedded jetty), they are &#8220;provided&#8221; scope because they are only used during development / testing (&#8220;test&#8221; scope does not works with gwt-maven plugin). The last two derby dependencies  are only here for the datasource example.</p>
<p>For accessing jdni resources, you then need to define a java environment variable :</p>
<pre class="brush: bash; gutter: false">-Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory</pre>
<p>&nbsp;</p>
<p><strong>If you use Google plugin for Eclipse :</strong> edit the run / debug preferences of your project :</p>
<p><a href="http://www.kaleidofoundry.org/blog/wp-content/uploads/2012/09/eclipse-gwt-launcher.png"><img class="size-large wp-image-133 aligncenter" title="eclipse-gwt-launcher" src="http://www.kaleidofoundry.org/blog/wp-content/uploads/2012/09/eclipse-gwt-launcher-1024x671.png" alt="eclipse gwt launcher" width="640" height="419" /></a></p>
<p><strong>If you use the maven gwt plugin</strong> :</p>
<pre class="brush: bash; gutter: false">mvn gwt:run</pre>
<p><strong>To compile and install the final war plugin</strong> :</p>
<pre class="brush: bash; gutter: false">mvn clean install</pre>
<blockquote><p>Once the gwt application tested and compiled : If you works with apache tomcat under eclipse, I highly recommend the tomcat plugin (with its DevClassLoader for hot code replace) : <a href="http://www.eclipsetotale.com/tomcatPlugin.html">http://www.eclipsetotale.com/tomcatPlugin.html</a></p></blockquote>
<p style="text-align: center;">All works with google<strong> 2.5.0-rc1 </strong>too <img src='http://www.kaleidofoundry.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>To conclude, you can develop with gwt as though you worked on your prefered servlet container like tomcat / jetty &#8230; Without hack , gwt rpc servlets can now uses jndi resources like datasources, environment variables&#8230; A simple &#8220;war&#8221; project could be used for debugging or delivering your web application version.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kaleidofoundry.org/blog/2012/09/gwt-debug-jetty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
