2

我得到的问题是通过 JSP 获取详细信息。我正在使用以下版本:jna-4.2.2.jar、slf4j-api-1.7.21.jar、slf4j-simple-1.7.21.jar、jna-platform-4.2.2.jar、oshi-core-2.3。 jar 问题是每当我从 JSP 执行下面的代码时,我都会收到下面所述的错误,但是在普通的 Java App 中它可以正常工作而没有任何错误?

这是 JSP 的错误吗?或者有没有其他方法可以在 JSP 中调用它?

<%@page import="oshi.hardware.HardwareAbstractionLayer"%>
<%@page import="oshi.software.os.OperatingSystem"%>
<%@page import="oshi.SystemInfo"%>
<%
    SystemInfo si = new SystemInfo();
    OperatingSystem os = si.getOperatingSystem();
     HardwareAbstractionLayer hal = si.getHardware();
     out.println(hal.getProcessor());
%>

错误是:

Warning:   StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NoSuchMethodError: com.sun.jna.IntegerType.<init>(IJZ)V
    at com.sun.jna.platform.win32.WinDef$DWORD.<init>(WinDef.java:135)
    at com.sun.jna.platform.win32.WinDef$DWORD.<init>(WinDef.java:125)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at java.lang.Class.newInstance(Class.java:442)
    at com.sun.jna.NativeMappedConverter.defaultValue(NativeMappedConverter.java:47)
    at com.sun.jna.NativeMappedConverter.<init>(NativeMappedConverter.java:41)
    at com.sun.jna.NativeMappedConverter.getInstance(NativeMappedConverter.java:29)
    at com.sun.jna.Structure.calculateSize(Structure.java:717)
    at com.sun.jna.Structure.allocateMemory(Structure.java:251)
    at com.sun.jna.Structure.<init>(Structure.java:153)
    at com.sun.jna.Structure.<init>(Structure.java:143)
    at com.sun.jna.Structure.<init>(Structure.java:139)
    at com.sun.jna.Structure.<init>(Structure.java:130)
    at com.sun.jna.platform.win32.WinBase$MEMORYSTATUSEX.<init>(WinBase.java:595)
    at oshi.hardware.platform.windows.WindowsGlobalMemory.<init>(WindowsGlobalMemory.java:40)
    at oshi.hardware.platform.windows.WindowsHardwareAbstractionLayer.getMemory(WindowsHardwareAbstractionLayer.java:50)
    at org.apache.jsp.api.cpuload_jsp._jspService(cpuload_jsp.java:62)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

请提出一些解决该问题的方法。

4

2 回答 2

1

看起来您缺少两个 jar 文件

如果您使用的是 Netbeans:

转到项目属性 > 库 > 编译 > 添加 JAR

现在添加两个文件:-

javax.json-1.0.4.jar

javax.json-api-1.0.jar

你可以从这里下载它们jsonjson-api

有关文档参考,请参见此处:https ://jsonp.java.net/download.html

于 2016-04-21T10:28:21.077 回答
0

堆栈跟踪行号表明您正在使用 jna-platform-4.2.2,但不知何故,您的代码在 jna-4.2.2.jar 以外的其他地方找到了 com.sun.jna.IntegerType。

尝试运行此代码:

Class klass = com.sun.jna.IntegerType.class;
URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class");

然后输出 location.toString() 并验证它是否在 jna-4.2.2 jar 中。你应该得到类似的结果

jar:file:/ ...path to jar... /jna-4.2.2.jar!/com/sun/jna/IntegerType.class

如果没有,您已经找到了 Java 类加载器加载错误类的位置。然后找出如何从该备用位置排除该类(删除坏 jar,使用更新的资源包等)

于 2016-04-21T17:22:47.030 回答