GWT 1.6でJNDIを使う方法 at ミネルヴァの梟は黄昏とともに飛び始める

ミネルヴァの梟は黄昏とともに飛び始める

Follow me on Twitter: http://www.twitter.com/dddaisuke

GWT 1.6でJNDIを使う方法

with 3 comments

gw-00001

Google Plugin for Eclipseにも同包されている、Google Web Toolkitの最新バージョンである1.6からは、サーブレットコンテナがTomcatからJettyに変更されています。

これは、Google App EngineのサーブレットコンテナにJettyが採用されている事と関係があると思いますが、古いGWTのローカル環境では動作していたJNDIが動作しなくなったという問題があります。

これは、業務で利用されている方は非常にお困りでないかと思います。私は困りました。。。

以下、Google Plugin for Eclipseで作成したGWT プロジェクトでJNDIを使えるようにする方法。

  1. プロジェクトディレクトリ直下に[lib]ディレクトリを作成し、jetty-naming-6.1.11.jarjetty-plus-6.1.11.jarを、コピーしクラスパスを通す。
  2. jetty-web.xmlを[war/WEB-INF]にコピーする。(jetty-web.xmlの書き方は以下の通り)
  3. プロジェクト名を右クリック[Run As]-[Web Application]で一度実行し、Run設定ファイルを自動生成させる。(この設定を行いたいプロジェクトを過去に1回でも実行していればOK)
  4. プロジェクト名を右クリック[Run As]-[Run Configurations...]で表示されるダイアログの[Arguments]タブの”VM arguments”に[-Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory]を記入し、[Apply]ボタンをクリック
  5. 以後、この設定で実行するとJNDIを正しく設定ファイルからロードします。

・MySQL用の設定です。他のDBの設定方法はこちらから。

< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

<configure class="org.mortbay.jetty.webapp.WebAppContext">

    <new id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">

        <arg>java:comp/env/jdbc/screenshot</arg>
        <arg>
            <new class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                <set name="Url">jdbc:mysql://testdb.soba-project.com:3306/testservice</set>
                <set name="User">test</set>
                <set name="Password">test</set>
            </new>
        </arg>
   </new>

</configure>

本番はTomcatで動作させたい人は、[war]ディレクトリに[META-INF]ディレクトリを作成して、従来のJNDI設定を書いたcontext.xmlを設置しておくと便利かも。

====================以下、検索用====================

GWT 1.6
Google Web Toolkit 1.6
Google Plugin for Eclipse
Tomcat
Jetty
context.xml
ROOT.xml
jetty-web.xml
JNDI
DB
c3p0
dbcp
Atomikos
MySQL
SQL Server
Oracle
PostgraSQL
Sybase
DB2

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.soba_project.portal.analyzer.server.SobaPortalAnalyzerServiceImpl.init(SobaPortalAnalyzerServiceImpl.java:39)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:342)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
com.google.gwt.user.client.rpc.StatusCodeException: The call failed on the server; see server log for details
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

Written by daisuke

5月 19th, 2009 at 1:48 pm

3 Responses to 'GWT 1.6でJNDIを使う方法'

Subscribe to comments with RSS or TrackBack to 'GWT 1.6でJNDIを使う方法'.

  1. Hello Daisuke,
    I do not read Japanese. But could you resolve the problem with com.google.gwt.user.client.rpc.StatusCodeException: The call failed on the server; see server log for details
    ?

    chep

    28 11月 09 at 5:10:58

  2. Hi chep,

    Thanks for your comment.
    Now changed servlet container to Jetty from GWT 1.6.

    It becomes impossible to use the setting of JNDI that moved with GWT that is older than 1.6 therefore.

    If you using “Google Plugin for Eclipse”, resolve your problem this following configuration.

    1.create “lib” direcotry in right under the project directory.
    2.copy “jetty-naming-6.1.11.jar” & “jetty-plus-6.1.11.jar” to lib directory and add to classpath.
    3.copy “jetty-web.xml” to “war/WEB-INF” (how to write jetty-web.xml refer to the above-mentioned. it’s configuration for MySQL.)
    4.To generate the configuration for run automatically, it running once. right click on the project name. and select [Run As] – [Web Application]
    5.right click on the project name. and select [Run As] – [Run Configurations...], [Arguments]tab [-Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory]to "VM arguments" finally click [Apply].

    cheers

    Daisuke

    30 11月 09 at 10:51:27

  3. Thank you for your attention. I found my problem. The error was because I put field with type Date in my RPC class. The problem has gone when I commented the field.

    Sincerely,
    cheprus

    chep

    30 11月 09 at 18:53:33

Leave a Reply