很简单的,myeclipse配置好就行了,不要.bat的,按照他的向导走
解决方案 »
- hibernate 怎么使用原始的SQL 语句进行insert update delete 操作
- Apache Tomcat/7.0.30
- getHibernateTemplate().get 查询返回null--求教!
- 在tomcat里边跑的时候没有问题,但是在apusic里边却报错
- session.save(object)不执行!!!一对多list映射,save(多方)不执行。。
- apache2 问题... 急
- java大一作业!!十一点前在线等!!!
- 关于js的一个菜鸟问题
- 在class文件内生成了有30多列、20行的Excel文件,很快就读出来,如是30行以上
- js如何删除分页数据,请大神帮忙。急!在线等
- 事务出错:You cannot rollback during a managed transaction!
- 请问Tomcat中beans应该放在什么目录下???急!!急!!!啊
package jbejb;import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;public class SayHelloTestClient1 extends Object {
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 100;
private boolean logging = true;
private SayHelloHome sayHelloHome = null;
private SayHello sayHello = null; //Construct the EJB test client
public SayHelloTestClient1() {
initialize();
}
private static Context getInitialContext() throws NamingException {
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");
return new InitialContext(environment);
} public void initialize() {
long startTime = 0;
if (logging) {
log("Initializing bean access.");
startTime = System.currentTimeMillis();
} try {
//get naming context
Context context = this.getInitialContext(); //look up jndi name
Object ref = context.lookup("SayHello");
//look up jndi name and cast to Home interface
sayHelloHome = (SayHelloHome) PortableRemoteObject.narrow(ref, SayHelloHome.class);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded initializing bean access through Home interface.");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed initializing bean access.");
}
e.printStackTrace();
}
} //----------------------------------------------------------------------------
// Methods that use Home interface methods to generate a Remote interface reference
//---------------------------------------------------------------------------- public SayHello create() {
long startTime = 0;
if (logging) {
log("Calling create()");
startTime = System.currentTimeMillis();
}
try {
sayHello = sayHelloHome.create();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: create()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: create()");
}
e.printStackTrace();
} if (logging) {
log("Return value from create(): " + sayHello + ".");
}
return sayHello;
} //----------------------------------------------------------------------------
// Utility Methods
//---------------------------------------------------------------------------- private void log(String message) {
if (message == null) {
System.out.println("-- null");
return ;
}
if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
}
else {
System.out.println("-- " + message);
}
}
//Main method public static void main(String[] args) {
SayHelloTestClient1 client = new SayHelloTestClient1();
try{
SayHello hi=client.create();
System.out.println(hi.sayHello());
}
catch(Exception e){
e.printStackTrace();
}
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
}
}
Context ctx=new InitialContext("java:comp/env");
这一句是怎么出来的?“java:comp/env”在哪里定义的?可以自行定义别的吗?好像jboss中也是这么做的。希望各位高手解答。