Issue with JNA when working with JSP

162 views
Skip to first unread message

Ashish Patel

unread,
Apr 21, 2016, 12:25:11 PM4/21/16
to Java Native Access
Hello,
I am facing issue while working with JNA on JSP.
I always gets this error "java.lang.NoSuchMethodError: com.sun.jna.IntegerType.<init>(IJZ)V"
Here is my code
<%@page import="com.sun.jna.platform.win32.Kernel32"%>
<%@page import="com.sun.jna.platform.win32.WinBase.MEMORYSTATUSEX"%>
<%  MEMORYSTATUSEX _memory = new MEMORYSTATUSEX(); %>
<html>
<body>
Hello World!
</body>
</html>

Upon executing above code following error appears

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 org.apache.jsp.index_jsp._jspService(index_jsp.java:68)
    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)

Any luck?

Timothy Wall

unread,
Apr 21, 2016, 5:52:44 PM4/21/16
to jna-...@googlegroups.com
Probably a version mismatch.  Set jna.debug_load.jna=true system property to see where jna is coming from

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashish Patel

unread,
Apr 22, 2016, 2:28:57 AM4/22/16
to Java Native Access
Looks like it didnt help
I have tried to see where jna is comming from by using 
Class klass = com.sun.jna.IntegerType.class;
URL location
= klass.getResource('/' + klass.getName().replace('.', '/') + ".class");



the output was 
bundle://204.0:1/com/sun/jna/IntegerType.class

Furthermore  I try to execute the code 

<%  MEMORYSTATUSEX _memory = new MEMORYSTATUSEX(); %>
Gave me the same error. So I tried to manually load the Property which also didnt help
String prop=p.getProperty("java.class.path");
p.setProperty("java.class.path", prop+";D:\\p\\jars\\jna-4.2.2.jar;D:\\p\\jars\\jna-platform-4.2.2.jar");
Still no luck.
And the main thing is that this problem occurs only when using JSP files over Glassfish server.

Timothy Wall

unread,
Apr 26, 2016, 10:44:17 AM4/26/16
to jna-...@googlegroups.com
Check your server configuration for old versions of jna.

Ashish Patel

unread,
Apr 26, 2016, 11:33:11 AM4/26/16
to Java Native Access
I am having the latest JNA version 4.2.2 for both platform and jna

mbla...@doppel-helix.eu

unread,
Apr 26, 2016, 12:32:25 PM4/26/16
to Java Native Access


Am Dienstag, 26. April 2016 16:44:17 UTC+2 schrieb Timothy Wall:
Check your server configuration for old versions of jna.


This was also opened as a bug against jna on github:

https://github.com/java-native-access/jna/issues/641

Long story short: Glassfish/Payara/other depends on libpam4j, which bundles an older version of JNA (from the timestamp in the zip it is about 6 years old), this seems to leak into the classpath of webapplications. I suggested to raise a bug on the glassfish jira and/or payara, but this was turned down and it was stated, that Ashish will move to tomcat - whether that is a solution or if other dependencies collide there remains to be seen.

HTH

Matthias
Reply all
Reply to author
Forward
0 new messages