2012-03-14 3 views
3

이 질문이 반복적으로 보이는 경우 실례지만 기존 게시물의 검색 결과에서 실행 가능한 해결책을 찾지 못했습니다.eclipse에서 GWT/Jetty와의 연결 풀을 어떻게 설정합니까?

나는 JDBC 연결 풀을 사용하는 웹 응용 프로그램을 가지고 있습니다. 연결 풀 자원은 war 파일의 meta-inf/context.xml에 정의됩니다. 내가 tomcat에 war 파일을 배포하면이 파일은 tomcat의 conf/catalina/localhost 폴더에 복사되고 내 war 파일의 이름과 일치하도록 바뀝니다.

Context envCtx = (Context) new InitialContext().lookup("java:comp/env"); 
datasource = (DataSource) envCtx.lookup("jdbc/MYDB"); 

내 context.xml에 정의 다음과 같은 자원이 있습니다 : 내 코드는 다음과 연결의 데이터 소스 개체를 가져옵니다 전쟁 파일이 바람둥이에 배포 될 때

<Resource name="jdbc/MYDB" 
     auth="Container" 
     type="javax.sql.DataSource" 
     driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
     username="username" 
     password="password" 
     url="jdbc:sqlserver://myremote.database.server:1433;databaseName=testdb" 
     /> 

이 모든 잘 작동합니다.

그러나 Eclipse에서 개발하는 동안 및 GWT 종속성 때문에 GWT의 내장 된 jetty 컨테이너를 사용하여 디버깅해야합니다. 나는이 작업을 수행 할 때

는 InitialContext를() 호출은 다음과 같은 메시지와 함께 실패 : 나는 전쟁의 WEB-INF에 부두 - env.xml를 사용하려고

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 

하지만 같은 (작동 중 하나를하지 않았다 오류), 아마도 jetty-env.xml 또는 다른 구문 오류가 있습니다. 여기

내 부두-ENV이다 : 나는 부두-web.xml 파일에 부두 - env.xml의 이름을 변경 한 경우,

<?xml version="1.0"?> 
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> 
<Configure id="Server" class="org.eclipse.jetty.server.Server"> 
<New id="OTMFTDB" class="org.eclipse.jetty.plus.jndi.Resource"> 
    <Arg></Arg> 
    <Arg>jdbc/MYDB</Arg> 
    <Arg> 
     <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource"> 
      <Set name="User">username</Set> 
      <Set name="Password">password</Set> 
      <Set name="DatabaseName">testdb</Set> 
      <Set name="ServerName">myremote.database.server</Set> 
      <Set name="PortNumber">1433</Set> 
     </New> 
    </Arg> 
</New> 
</Configure> 

마지막 한가지, 다음의 I 때 503 HTML 오류가 브라우저에 연결하려고합니다. 이클립스는 다음 오류를 보여줍니다 : [WARN] 컨텍스트 com.g[email protected]111a20c {/, E : \ dev \ src \ servers \ webservice \ war}의 시작 실패 java .lang.ClassNotFoundException : org.eclipse.jetty.server.Server)

그래서 jetty-env가로드되지 않았고 jetty-web은 있다고 생각하지만 제 부두 - 웹은 분명 GWT의 부두 설정을 방해합니다.

답변

2

당신은 org.eclipse.jetty.server.Server누락,하지만 난 그게 바로 클래스하지라고 생각합니다. GWT 2.5.1은 부두 6.1.11을 사용하고 thisorg.eclipse.jetty 부두 7의 패키지가 아니라 6!

나는 비슷한 문제가있어서 프로젝트에 jetty-naming과 jetty-plus 라이브러리를 추가하여 해결했습니다. 받는다는없이

<dependency> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>jetty-naming</artifactId> 
    <version>6.1.11</version> 
</dependency> 
<dependency> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>jetty-plus</artifactId> 
    <version>6.1.11</version> 
</dependency> 

당신이 웹에서 jetty-namingjetty-plus 항아리를 다운로드 할 수 있습니다 : 나는 pom.xml 파일이 추가 그래서 받는다는 프로젝트입니다.

내 리소스는 PostgreSQL JDBC 드라이버입니다. 이제 모든 것이 작동합니다 - 호스팅 모드에서는 jetty-web.xml에서 리소스 구성을로드합니다.그리고 전쟁을 구축하고 Tomcat에 배포하면 context.xml에서 리소스를 가져옵니다.

의 context.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<Context antiJARLocking="true" path="/web"> 
    <Resource auth="Container" driverClassName="org.postgresql.Driver" 
     maxActive="100" maxIdle="30" maxWait="200" name="jdbc/postgres" 
     username="testuser" password="testpass" type="javax.sql.DataSource" 
     url="jdbc:postgresql://localhost:5433/resolver" /> 
</Context> 

부두-web.xml의 :

<resource-ref> 
    <description>Postgres Connection pool datasource</description> 
    <res-ref-name>jdbc/postgres</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

데이터 소스가이 방법을로드 (:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> 
<Configure class="org.mortbay.jetty.webapp.WebAppContext"> 
    <New id="GWT_HOSTED_MODE_DB" class="org.mortbay.jetty.plus.naming.Resource"> 
     <Arg>java:/comp/env/jdbc/postgres</Arg> 
     <Arg> 
      <New class="org.apache.commons.dbcp.BasicDataSource"> 
       <Set name="driverClassName">org.postgresql.Driver</Set> 
       <Set name="url">jdbc:postgresql://localhost:5433/resolver</Set> 
       <Set name="username">testuser</Set> 
       <Set name="password">testpass</Set> 
      </New> 
     </Arg> 
    </New> 
</Configure> 

이 또한 내 web.xml 파일이 참조를 포함

단순화) :

DataSource dataSource = (DataSource) new InitialContext().lookup("java:/comp/env/jdbc/postgres"); 
+0

자세한 답변을 보내 주셔서 감사합니다. 나는 그것을 시도하고 그것은 나를 위해 작동하지 않았다. 그 이유는 내가 새로운 GWT (2.6.0)를 사용하고 있기 때문입니다.이 SO 응답 (https://stackoverflow.com/a/17592318)에 기반하여 부두 8.1.12를 사용하고 있다고 생각합니다. 구성 파일과 클래스 이름이 다를 것이라고 생각하지만 온라인 Jetty 8 설명서를 찾을 수 없습니다 (Jetty 9.3.x 만 사용 가능). 어쨌든 Jetty 9 (여기 : https://www.eclipse.org/jetty/documentation/9.3.x/using-jetty-jndi.html)에 대한 안내를 따르려고합니다. 통찰력이 있다면 나와 공유하십시오. – leeyuiwah

관련 문제