求助關於EJB的部署問題(小弟是初學者,請各位大哥看一下)

pwy1983發表於2005-09-05
在weblogic部署EJB時出現以下紅色英文字母是什麼出錯了:


Exception:weblogic.management.ApplicationException: prepare failed for bank2 Module: bank2 Error: Exception preparing module: EJBModule(bank2,status=NEW) Unable to deploy EJB: bank2.jar from bank2.jar: Compiler failed executable.exec at weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:274) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:476) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:407) at weblogic.ejb20.deployer.EJBDeployer.runEJBC(EJBDeployer.java:493) at weblogic.ejb20.deployer.EJBDeployer.compileJar(EJBDeployer.java:784) at weblogic.ejb20.deployer.EJBDeployer.compileIfNecessary(EJBDeployer.java:700) at weblogic.ejb20.deployer.EJBDeployer.prepare(EJBDeployer.java:1339) at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:498) at weblogic.j2ee.J2EEApplicationContainer.prepareModule(J2EEApplicationContainer.java:3142) at weblogic.j2ee.J2EEApplicationContainer.prepareModules(J2EEApplicationContainer.java:1583) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1227) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1070) at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.prepareContainer(SlaveDeployer.java:2513) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.createContainer(SlaveDeployer.java:2463) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2379) at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:866) at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:594) at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:508) at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178) java.io.IOException: Compiler failed executable.exec at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvoker.java:469) at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:328) at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:336) at weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:270) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:476) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:407) at weblogic.ejb20.deployer.EJBDeployer.runEJBC(EJBDeployer.java:493) at weblogic.ejb20.deployer.EJBDeployer.compileJar(EJBDeployer.java:784) at weblogic.ejb20.deployer.EJBDeployer.compileIfNecessary(EJBDeployer.java:700) at weblogic.ejb20.deployer.EJBDeployer.prepare(EJBDeployer.java:1339) at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:498) at weblogic.j2ee.J2EEApplicationContainer.prepareModule(J2EEApplicationContainer.java:3142) at weblogic.j2ee.J2EEApplicationContainer.prepareModules(J2EEApplicationContainer.java:1583) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1227) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1070) at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.prepareContainer(SlaveDeployer.java:2513) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.createContainer(SlaveDeployer.java:2463) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2379) at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:866) at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:594) at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:508) at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)

[Deployer:149033]preparing application bank2 on myserver

[Deployer:149033]failed application bank2 on myserver

[Deployer:149034]An exception occurred for task [Deployer:149026]Deploy application bank2 on myserver.: Exception:weblogic.management.ApplicationException: prepare failed for bank2 Module: bank2 Error: Exception preparing module: EJBModule(bank2,status=NEW) Unable to deploy EJB: bank2.jar from bank2.jar: Compiler failed executable.exec at weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:274) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:476) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:407) at weblogic.ejb20.deployer.EJBDeployer.runEJBC(EJBDeployer.java:493) at weblogic.ejb20.deployer.EJBDeployer.compileJar(EJBDeployer.java:784) at weblogic.ejb20.deployer.EJBDeployer.compileIfNecessary(EJBDeployer.java:700) at weblogic.ejb20.deployer.EJBDeployer.prepare(EJBDeployer.java:1339) at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:498) at weblogic.j2ee.J2EEApplicationContainer.prepareModule(J2EEApplicationContainer.java:3142) at weblogic.j2ee.J2EEApplicationContainer.prepareModules(J2EEApplicationContainer.java:1583) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1227) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1070) at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.prepareContainer(SlaveDeployer.java:2513) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.createContainer(SlaveDeployer.java:2463) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2379) at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:866) at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:594) at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:508) at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178) java.io.IOException: Compiler failed executable.exec at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvoker.java:469) at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:328) at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:336) at weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:270) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:476) at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:407) at weblogic.ejb20.deployer.EJBDeployer.runEJBC(EJBDeployer.java:493) at weblogic.ejb20.deployer.EJBDeployer.compileJar(EJBDeployer.java:784) at weblogic.ejb20.deployer.EJBDeployer.compileIfNecessary(EJBDeployer.java:700) at weblogic.ejb20.deployer.EJBDeployer.prepare(EJBDeployer.java:1339) at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:498) at weblogic.j2ee.J2EEApplicationContainer.prepareModule(J2EEApplicationContainer.java:3142) at weblogic.j2ee.J2EEApplicationContainer.prepareModules(J2EEApplicationContainer.java:1583) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1227) at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:1070) at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.prepareContainer(SlaveDeployer.java:2513) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.createContainer(SlaveDeployer.java:2463) at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2379) at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:866) at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:594) at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:508) at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178) .

原始檔如下:

1.BankBean:

package bankbmp;

// The source files use explicit imports instead of importing a package.*.
// While this is a matter of personal preference, using explicit imports
// allows the user to quickly learn which package contains a class.
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javax.ejb.DuplicateKeyException;
import javax.ejb.EntityContext;
import javax.ejb.EntityBean;
import javax.ejb.EJBException;
import javax.ejb.NoSuchEntityException;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class BankBean implements EntityBean {

// The next three variables are instance variables, but are not tied
// to a particular identity/primary key. These variables are set in
// the setEntityContext method before the bean has an identity and
// are used for the lifetime of the bean instance.

private EntityContext ctx;
private DataSource dataSource;
private String tableName;

private Integer accountID; //primary key
private String ownerName;
private float accountValue;
private int accountLevel;


// The setEntityContext method receives an EntityContext reference
// which it stores in a member variable. It also uses the EJB's
// environment context to look up some deployment-specific
// parameters. When the EJB is deployed, the deployer will specify
// values for the tableName and poolName parameters in the
// ejb-jar.xml which match the deployment environment. This allows
// these values not to be hard-coded into the bean. The
// setEntityContext method also gets a DataSource object from the
// environment. This will be used to get database connections from
// the connection pool.

public void setEntityContext(EntityContext c) {

ctx = c;

try {
Context envCtx = (Context) new InitialContext().lookup("java:/comp/env");

tableName = (String) envCtx.lookup("tableName");

String poolName = (String) envCtx.lookup("poolName");

dataSource = (DataSource) envCtx.lookup("/jdbc/"+poolName);
} catch (NamingException ne) {
// EJB was not deployed properly
throw new EJBException(ne);
}

}

public void unsetEntityContext() {
ctx = null;
}

public Integer ejbCreate(int accountID,String ownerName,
float accountValue,int accountLevel)
{
this.accountID = new Integer(accountID);
this.ownerName = ownerName;
this.accountValue =accountValue;
this.accountLevel = accountLevel;

Connection con = null;
PreparedStatement ps = null;
Statement stmt=null;

try {
con = dataSource.getConnection();
System.out.println("----\nConnect successful");
ps = con.prepareStatement("insert into "+tableName+
" (accountID,ownerName,accountValue,accountLevel) values(?,?,?,?)");
ps.setInt(1,accountID);
ps.setString(2,ownerName);
ps.setFloat(3,accountValue);
ps.setInt(4,accountLevel);
ps.executeUpdate();
System.out.println(accountID+" "+ownerName);
System.out.println(accountValue+" "+accountLevel);
System.out.println("insert successful:"+tableName);
//when use no-transaction sataSource add follow:
//con.commit();
return this.accountID;
} catch (SQLException sqe){
try {
ejbFindByPrimaryKey(this.accountID);
throw new DuplicateKeyException("A Bank with bank "+
"account: "+accountID+" already exists.");
} catch (Exception Ignore){}
System.out.println("Insert failed");
//sqe.printStackTrace();
throw new EJBException(sqe);
} finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
} catch (Exception ignore) {}
}
}

// This implementation requires no post-create initialization so
// this required method is empty
public void ejbPostCreate(int accountID,String ownerName,
float accountValue,int accountLevel) {}

// The ejbRemove method is responsible for deleting the instance
// from the database. This method uses a SQL delete to delete the instance.
public void ejbRemove() throws RemoveException
{
Connection con = null;
PreparedStatement ps = null;
try {
System.out.println("ejbRemove()");
con = dataSource.getConnection();
ps = con.prepareStatement("delete from "+tableName+
" where accountID=?");
ps.setInt(1, accountID.intValue());
if (ps.executeUpdate() < 1) {
throw new RemoveException ("Error removing Bank with accountID: "+accountID);
}
} catch (SQLException sqe) {
throw new EJBException (sqe);
} finally{
try {
if(ps != null) ps.close();
if(con != null) con.close();
} catch (Exception ignore) {}
}
}

// ejbLoad reads the entity bean's current state from the database
// and assigns the values to its member variables. The primary key
// is available from the EntityContext member variable. If the
// entity bean no longer exists, NoSuchEntityException is thrown.
// This might occur if the entity bean was deleted by another client
// or directly from the database.
public void ejbLoad() {
accountID = (Integer) ctx.getPrimaryKey();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
System.out.println("ejbLoad()");
con = dataSource.getConnection();
ps = con.prepareStatement("select ownerName,accountValue,accountLevel from "+
tableName+ " where accountID=?");
ps.setInt(1, accountID.intValue());
ps.executeQuery();
rs = ps.getResultSet();

if (rs.next()) {
ownerName = rs.getString(1);
accountValue = rs.getFloat(2);
accountLevel = rs.getInt(3);
} else {
throw new NoSuchEntityException("Bank with bank "+
"account: "+accountID+" no longer exists.");
}
} catch (SQLException sqe) {
throw new EJBException(sqe);
} finally {
try {
if (rs != null) rs.close();
if (ps != null) ps.close();
if (con != null) con.close();
} catch (Exception ignore) {}
}
}

// The ejbStore method will be called to write the entity bean's
// state back to the database. The primary key field is not written
// since primary keys should never change. An optimized version of
// this bean could also skip writing the name field since it is
// never updated.
public void ejbStore(){
Connection con = null;
PreparedStatement ps = null;
try {
System.out.println("ejbStore()");
con = dataSource.getConnection();
ps = con.prepareStatement("update "+tableName+
" SET ownerName=?,accountValue=?,accountLevel=? where accountID=?");

ps.setString(1, ownerName);
ps.setFloat(2, accountValue);
ps.setInt(3, accountLevel);
ps.setInt(4, accountID.intValue());

ps.executeUpdate();
} catch (SQLException sqe) {
System.out.println("ejbStore() error");
//throw new EJBException(sqe);
} finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
} catch (Exception ignore) {}
}
}

// The ejbActivate and ejbPassivate methods are required by the
// EntityBean interface, but this bean does not use these callbacks.
public void ejbActivate() {}
public void ejbPassivate() {}

// The ejbFindByPrimaryKey method needs to test whether the passed
// key exists in the database. If the select returns a row then the
// primary key is returned. If the key does not exist, an
// ObjectNotFoundException is thrown.
public Integer ejbFindByPrimaryKey(Integer pk)
throws ObjectNotFoundException
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
System.out.println("ejbFindByPrimaryKey()");
con = dataSource.getConnection();
ps = con.prepareStatement("select accountID from "+tableName+
" where accountID=?");
ps.setInt(1, pk.intValue());
ps.executeQuery();

rs = ps.getResultSet();

if (rs.next()) {
return pk;
} else {
throw new ObjectNotFoundException ("Bank with bank "+
"account: "+accountID+" no longer exists.");
}
} catch (SQLException sqe) {
//throw new EJBException (sqe);
throw new EJBException("ejbFindByPrimaryKey() error");
} finally {
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (Exception ignore) {}
}
}
// The ejbFindBankLevel method returns a Collection of
// Banks which match the query. The finder method returns a
// Collection of primary keys. The EJB container will convert these
// into EJBObject references and return them to the client. If now
// primary keys match the query, an empty Collection is returned.
public Collection ejbFindBankLevel(int accountLevelValue) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;

ArrayList keys = new ArrayList();
try {
con = dataSource.getConnection();
ps = con.prepareStatement("select accountID from "+tableName+
" where accountLevel=?");
ps.setInt(1, accountLevelValue);
ps.executeQuery();

rs = ps.getResultSet();
while (rs.next()) {
keys.add(new Integer(rs.getInt(1)));
}
return keys;
} catch (SQLException sqe) {
//throw new EJBException (sqe);
throw new EJBException("get PK error");
} finally {
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (Exception ignore) {}
}
}
// These methods implement the business methods defined in the
// Bank Remote interface.
public String getownerName() { return ownerName; }
public Integer getaccountID() { return accountID; }
public float getaccountValue(){return accountValue; }
public int getaccountLevel() { return accountLevel; }
public void setaccountLevel(int accountLevel) {
this.accountLevel = accountLevel;
}
}

BankHome:

package bankbmp;

import java.rmi.RemoteException;
import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.EJBHome;

public interface BankHome extends EJBHome {

// create method
public Bank create(int accountID, String ownerName,float accountValue,int accountLevel)
throws CreateException, RemoteException;

// finders
public Bank findByPrimaryKey(Integer accountID)
throws FinderException, RemoteException;

public Collection findBankLevel(int accountLevel)
throws FinderException, RemoteException

}

Bank:

package bankbmp;

import java.rmi.RemoteException;

import javax.ejb.EJBObject;


public interface Bank extends EJBObject {

public String getownerName() throws RemoteException;

public Integer getaccountID() throws RemoteException;

public int getaccountLevel() throws RemoteException;

public float getaccountValue() throws RemoteException;

public void setaccountLevel(int accountLevel) throws RemoteException;
}

ejb-jar:

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>


<!-- Generated XML! -->

<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>theBankEJB</ejb-name>
<home>bankbmp.BankHome</home>
<remote>bankbmp.Bank</remote>
<ejb-class>bankbmp.BankBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<primkey-field>accountID</primkey-field>
<env-entry>
<env-entry-name>tableName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>t_BankAccount</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>poolName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>dbpool</env-entry-value>
</env-entry>
<resource-ref>
<res-ref-name>jdbc/dbpool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
</enterprise-beans>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>theBankEJB</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>
weblogic-ejb-jar:

<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN' 'http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd'>


<!-- Generated XML! -->
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>theBankEJB</ejb-name>
<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/dbpool</res-ref-name>
<jndi-name>JTA-dataSource</jndi-name>
</resource-description>
</reference-descriptor>

<jndi-name>theBankEJB</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
以下是bank.jar的目錄:

META -INF/ejb-jar.xml weblogic-ejb-jar

bankbmp/BankBean.class Bank.class Bank.class
我只是在BankBean裡新增了方法public float getaccountValue(){return accountValue; }和在遠端介面新增了相對應的方法 public float getaccountValue() throws RemoteException;所部署的EJB就部署不了

如果把上述的方法語句去掉卻可以部署

這是為什麼呢

相關文章