1.public String find(int id) {
Query q = em.createNativeQuery("select * from emp where empno = ?1", Emp.class);
q.setParameter(1, id);
Emp e = null;
if (q.getSingleResult() != null) {
e = (Emp) q.getSingleResult();
}
JSONObject ja = null;
if (e == null) {
return "";
} else {
ja = JSONObject.fromObject(e);
return ja.toString();
}
}
Caused by: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
2. @WebMethod(operationName = "find")
public String find(@WebParam(name = "id") int id) {
return ejbRef.find(id);
}
3.public abstract java.lang.String com.sdl.testservers.ws.EmpService.find(int)
webservice掉用 EJB的方法,ja = JSONObject.fromObject(e);运行到这一行就报错,提示找不到org/apache/commons/lang/exception/NestableRuntimeException。
但是我的jar包是全的,
为什么呢?求大神
是不是版本的问题
不确定是不是版本问题,但是我换过几个版本,问题依然存在
你Jar包的图也没截全,可能是jar包重复了,也可能是你并没有刷新工程,导致部署的项目里面少Jar包。
我用和你同样的jar包就可以实现json转换。
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>jsontest</groupId> 8 <artifactId>jsontest</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <dependencies> 11 <dependency> 12 <groupId>junit</groupId> 13 <artifactId>junit</artifactId> 14 <version>3.8.1</version> 15 <scope>test</scope> 16 </dependency> 17 <dependency> 18 <groupId>commons-lang</groupId> 19 <artifactId>commons-lang</artifactId> 20 <version>2.6</version> 21 </dependency> 22 <dependency> 23 <groupId>commons-beanutils</groupId> 24 <artifactId>commons-beanutils</artifactId> 25 <version>1.9.2</version> 26 </dependency> 27 <dependency> 28 <groupId>commons-logging</groupId> 29 <artifactId>commons-logging</artifactId> 30 <version>1.2</version> 31 </dependency> 32 <dependency> 33 <groupId>net.sf.ezmorph</groupId> 34 <artifactId>ezmorph</artifactId> 35 <version>1.0.6</version> 36 </dependency> 37 <dependency> 38 <groupId>commons-codec</groupId> 39 <artifactId>commons-codec</artifactId> 40 <version>1.3</version> 41 </dependency> 42 <dependency> 43 <groupId>commons-collections</groupId> 44 <artifactId>commons-collections</artifactId> 45 <version>3.2.1</version> 46 </dependency> 47 <dependency> 48 <groupId>net.sf.json-lib</groupId> 49 <artifactId>json-lib</artifactId> 50 <version>2.4</version> 51 <classifier>jdk15</classifier> 52 </dependency> 53 <dependency> 54 <groupId>junit</groupId> 55 <artifactId>junit</artifactId> 56 <version>4.11</version> 57 <scope>test</scope> 58 </dependency> 59 </dependencies> 60 61 </project>
import net.sf.json.JSONObject; import org.junit.Test; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author: kischn * @date: 2015/10/28. */ public class JsonTest { @Test public void jsonTest(){ Map<String, String> map = new HashMap<String, String>(); map.put("name", "jack"); map.put("age", "12"); JSONObject jo = JSONObject.fromObject(map); System.out.println(jo.toString()); } }
{"name":"jack","age":"12"}
jar包没有重复,也是全的;
public static void main(String[] args) {
Emp e = new Emp();
e.setEname("test");
e.setDeptno(123);
JSONObject ja = null;
ja = JSONObject.fromObject(e);
System.out.println(ja+"|||||||||||||"+ja.getClass().getName());
}
这么写试了下没有问题,也是能转换的,说明jar包没问题。
这是个EJB的项目,EJB容器是glassfish提供的,然后把几个接口发布成webservice,用webservice测试的时候就会报错,提示找不到类。编译好的程序里面jar包也没问题,而且部署了很多次。见了鬼了
@冰原小白狼: 可以的话换个服务器试试吧~