java.lang.NoClassDefFoundError: net.sf.jni4net.Bridge

690 views
Skip to first unread message

Mr E

unread,
Sep 3, 2014, 1:13:10 AM9/3/14
to jni...@googlegroups.com
Hi,  Thanks for the jni4net bridge!  I have successfully built a Java application that calls a C# dll -- I have got the code working in Eclipse when run as a Java application.

What I would like to do now is call this method as part of a Lotus Notes plugin.

This java class sets up the Bridge and loads and registers the assembly DLL.  If the arguments passed (username and password) are validated by the C# dll, then 

public class Jni4netAuthenticator {

    /**

    * @param args

    * @throws IOException

    */

    public static void main(String[] args) throws IOException {

        System.out.println("classpath="+System.getProperty("java.classpath"));

        Bridge.setVerbose(true);

        Bridge.init();

        File proxyAssemblyFile = new File("SharpAuthenticator.j4n.dll");

        Bridge.LoadAndRegisterAssemblyFrom(proxyAssemblyFile);

        sharpauthenticator.Authenticator auth = new sharpauthenticator.Authenticator();

        boolean result = auth.Authenticate(args[0], args[1]);

        if (!result) {

            System.err.println("Not valid.");

        } else {

            System.out.println("Valid!");

        }

    }

}


When I run this as a Java application, using "user pass" as arguments, I get this in the console:


classpath=null

core loaded from C:/Users/Eric/workspace/jni4net/com.my.widget/jni4net.n-0.8.6.0.dll

clr.version         :v4.0.30319

clr.arch            :32bit

java.home           :C:\Lotus\Notes6\jvm

java.version        :1.6.0

sun.arch.data.model :32

loading SharpAuthenticator.j4n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null from C:\Users\Eric\workspace\jni4net\com.my.widget\SharpAuthenticator.j4n.dll

loaded SharpAuthenticator.j4n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null from C:\Users\Eric\workspace\jni4net\com.my.widget\SharpAuthenticator.j4n.dll

Valid!


So all compiles and runs correctly.  Now I would like to call the DLL from within the Notes plugin.  I am getting an error 


java.lang.NoClassDefFoundError: net.sf.jni4net.Bridge


when I call Jni4netAuthenticator from another method that is invoked from a menu command:


public class Command1Handler extends AbstractHandler {

public Object execute(ExecutionEvent event) throws ExecutionException {

String[] up = {"user","pass"};

try {

Jni4netAuthenticator.main(up);

} catch (IOException e) {

System.err.println("Bridge IOException.");

e.printStackTrace();

}

        }

}


It seems to be unable to find the jar file jni4net.j-0.8.6.0.jar.  It may have something to do with static methods.  I do not know.  


Here is the console log when the Lotus Notes menu item is selected:


Platform: 'Generic Web Application Server'

classpath=null

2014/09/03 00:58:00.440 SEVERE CLPDN0031E: Event loop exception ::class.method=com.ibm.rcp.personality.framework.internal.RCPWorkbenchAdvisor.eventLoopException() ::thread=main ::loggername=com.ibm.rcp.personality.framework.internal


java.lang.NoClassDefFoundError: net.sf.jni4net.Bridge

at com.my.widget.Jni4netAuthenticator.main(Jni4netAuthenticator.java:17)

at com.my.widget.Command1Handler.execute(Command1Handler.java:48)

at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:281)

at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)

at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)

at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)

at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)

at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:619)

at org.eclipse.ui.menus.CommandContributionItem.access$10(CommandContributionItem.java:605)

at org.eclipse.ui.menus.CommandContributionItem$4.handleEvent(CommandContributionItem.java:595)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4166)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3755)

at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384)

at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348)

at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200)

at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)

at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)

at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490)

at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)

at com.ibm.rcp.personality.framework.internal.RCPApplication.run(RCPApplication.java:67)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)

at java.lang.reflect.Method.invoke(Method.java:611)

at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)

at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:195)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)

at java.lang.reflect.Method.invoke(Method.java:611)

at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)

at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)

at org.eclipse.equinox.launcher.Main.run(Main.java:1236)

at org.eclipse.equinox.launcher.Main.main(Main.java:1212)

Caused by: java.lang.ClassNotFoundException: net.sf.jni4net.Bridge

at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)

at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)

at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)

at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)

at java.lang.ClassLoader.loadClass(ClassLoader.java:638)

... 40 more


Anyone know how to configure this correctly?  ;-)


Thanks in advance!


-Eric

Pavel Šavara

unread,
Sep 3, 2014, 2:18:30 AM9/3/14
to jni...@googlegroups.com

Two hints to check
- dlls in current directory of the process
- classloader and classpath

--
--
You received this message because you are subscribed to jni...@googlegroups.com
http://groups.google.com/group/jni4net?hl=en-GB?hl=en-GB
http://jni4net.sf.net/

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

Mr E

unread,
Sep 3, 2014, 9:53:22 AM9/3/14
to jni...@googlegroups.com
Thanks, Pavel,

By 'current directory' do you mean C:/Users/Eric/workspace/jni4net/com.my.widget/ where the SharpAuthenticator.j4n.jar is stored (and included as a reference library in the build path) 
or do you mean by 'current directory' C:\program files\lotus\notes\jvm\bin where the java.exe is?

In C:/Users/Eric/workspace/jni4net/com.my.widget/ I have stored the jni jar and dll files -- do these need to reside somewhere else, too?  I have added jni4net.j-0.8.6.0.jar to the referenced libraries in the build path. 

I am using Eclipse and do not quite know where/how to check/set the classpath.  When the code runs, 
System.out.println("classpath="+System.getProperty("java.classpath"));
it just returns "null".  

Here is the manifest file:

Manifest-Version: 1.0
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 com.ibm.notes.java.ui,
 com.ibm.rcp.ui,
 com.ibm.lotuslabs.context.service,
 org.eclipse.core.expressions
Bundle-Vendor: VendorName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.0.0
Bundle-Name: Widget Plug-in
Bundle-Activator: com.my.widget.Activator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.my.widget;singleton:=true
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.eclipse.ui.forms,
 org.eclipse.ui.forms.widgets

Thanks again!

-E

Pavel Šavara

unread,
Sep 3, 2014, 11:29:20 AM9/3/14
to jni...@googlegroups.com
Sorry, i'm too busy to go deeper on this one.
Reply all
Reply to author
Forward
0 new messages