Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Problem with Views using jNetPcap library(When I use jNetPcap in a View , I run into an error about "Cannot instansiate the view")
icon8.gif  Problem with Views using jNetPcap library [message #775284] Thu, 05 January 2012 18:06 Go to next message
Emad Heydari Beni is currently offline Emad Heydari BeniFriend
Messages: 3
Registered: January 2012
Location: Antwerp, Belgium
Junior Member
My system information:
Ubuntu 11.10
64-bit Architecture
Eclipse (Indigo Service Release 1)
Using jNetPcap wrapper to read network pcap-formatted offline files.


Step by step to face a problem:

  1. Open the Eclipse, make new Plug-in Project with "Rich Client Platform" check box enabled. (Default template: RCP application with a view)
  2. Right-click on the project and click properties; then go to the Java Build Path to add the jNetPcap Jar file. Add the Jar file.
  3. Take a look at the example of reading offline files using jNetPcap which is posted on its website.
  4. Open the default view to add some codes. (file: View.java) By default, it has a TableViewer with 3 inputs.
  5. I add my codes to this method of this class:


public void createPartControl(Composite parent) {
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL);
        viewer.setContentProvider(new ViewContentProvider());
        viewer.setLabelProvider(new ViewLabelProvider());
	// Provide the input to the ContentProvider
        viewer.setInput(new String[] {"One", "Two", "Three"});
		
        /*************************************************************************
		 *************************************************************************
		 *************************  My codes  ************************************
		 ************************************************************************* 
		 *************************************************************************/


        final StringBuilder errbuf = new StringBuilder(); // For any error msgs  
        final String file = "tests/test-l2tp.pcap";  
  
        System.out.printf("Opening file for reading: %s%n", file);  
  
        /*************************************************************************** 
         * Second we open up the selected file using openOffline call 
         **************************************************************************/  
        Pcap pcap = Pcap.openOffline(file, errbuf);  
  
        if (pcap == null) {  
            System.err.printf("Error while opening device for capture: "  
                + errbuf.toString());  
            return;  
        }  
  
        /*************************************************************************** 
         * Third we create a packet handler which will receive packets from the 
         * libpcap loop. 
         **************************************************************************/  
        PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {  
  
            public void nextPacket(PcapPacket packet, String user) {  
  
                System.out.printf("Received at %s caplen=%-4d len=%-4d %s\n",   
                    new Date(packet.getCaptureHeader().timestampInMillis()),   
                    packet.getCaptureHeader().caplen(), // Length actually captured  
                    packet.getCaptureHeader().wirelen(), // Original length  
                    user // User supplied object  
                    );  
            }  
        };  
  
        /*************************************************************************** 
         * Fourth we enter the loop and tell it to capture 10 packets. The loop 
         * method does a mapping of pcap.datalink() DLT value to JProtocol ID, which 
         * is needed by JScanner. The scanner scans the packet buffer and decodes 
         * the headers. The mapping is done automatically, although a variation on 
         * the loop method exists that allows the programmer to sepecify exactly 
         * which protocol ID to use as the data link type for this pcap interface. 
         **************************************************************************/  
        try {  
            pcap.loop(10, jpacketHandler, "jNetPcap rocks!");  
        } finally {  
        /*************************************************************************** 
         * Last thing to do is close the pcap handle 
         **************************************************************************/  
           pcap.close();  
        } 
	}



Continue: Then, I run the project as Eclipse Application and I see this Error stack in console tab of my Eclipse:

!SESSION 2012-01-05 18:49:44.071 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_23
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -product MyRCProject.product
Command-line arguments:  -product MyRCProject.product -data /home/emad/workspace/../runtime-MyRCProject.product -dev file:/home/emad/workspace/.metadata/.plugins/org.eclipse.pde.core/MyRCProject.product/dev.properties -os linux -ws gtk -arch x86_64 -consoleLog

!ENTRY org.eclipse.equinox.registry 4 1 2012-01-05 18:49:45.977
!MESSAGE Unable to create view ID MyRCProject.view: Plug-in "MyRCProject" was unable to instantiate class "myrcproject.View".
!STACK 0
java.lang.NoClassDefFoundError: org/jnetpcap/packet/PcapPacketHandler
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2406)
	at java.lang.Class.getConstructor0(Class.java:2716)
	at java.lang.Class.newInstance0(Class.java:343)
	at java.lang.Class.newInstance(Class.java:325)
	at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:184)
	at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
	at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
	at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
	at org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java:260)
	at org.eclipse.ui.internal.registry.ViewDescriptor.createView(ViewDescriptor.java:63)
	at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:327)
	at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:229)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
	at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
	at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:534)
	at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
	at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
	at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
	at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
	at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
	at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
	at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:643)
	at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:570)
	at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:568)
	at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:272)
	at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:981)
	at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2714)
	at org.eclipse.ui.internal.WorkbenchWindow$27.run(WorkbenchWindow.java:3023)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:3004)
	at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(WorkbenchWindow.java:799)
	at org.eclipse.ui.internal.Workbench$23.runWithException(Workbench.java:1224)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
	at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
	at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1595)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at myrcproject.Application.start(Application.java:20)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	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:344)
	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:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.ClassNotFoundException: org.jnetpcap.packet.PcapPacketHandler
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
	... 66 more



Help: Please help me, let me know if I missed any part in my project.
I should mention that I can read Offline pcap files in normal Java Project.
Source file: is attached to this topic.

[Updated on: Thu, 05 January 2012 18:08]

Report message to a moderator

Re: Problem with Views using jNetPcap library [message #775691 is a reply to message #775284] Fri, 06 January 2012 14:25 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

See http://wiki.eclipse.org/Eclipse_Plug-in_Development_FAQ#I.27m_using_third_party_jar_files_and_my_plug-in_is_not_working

PW


Re: Problem with Views using jNetPcap library [message #775779 is a reply to message #775691] Fri, 06 January 2012 17:00 Go to previous messageGo to next message
Emad Heydari Beni is currently offline Emad Heydari BeniFriend
Messages: 3
Registered: January 2012
Location: Antwerp, Belgium
Junior Member
[Problem is solved]

I have done two steps to fix the exceptions:



  1. According to dear Paul Webster Link, I've done some further steps
  2. Then, I found out that I forgot to copy libjnetpcap.so to the /usr/lib


Use this command in Ubuntu terminal:
sudo cp libjnetpcap.so /usr/lib
Re: Problem with Views using jNetPcap library [message #777000 is a reply to message #775779] Mon, 09 January 2012 16:27 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You also might be able to include it in your bundle-jar, license permitting. See http://litrik.blogspot.com/2007/08/secrets-of-bundle-nativecode.html and http://holistictendencies.wordpress.com/2011/03/28/bundle-nativecode-using-platform-specific-dlls-from-osgi/

PW


Previous Topic:Launcher error with product executable, but not with launcher.jar
Next Topic:Help to draw different images in table according element data?
Goto Forum:
  


Current Time: Thu Mar 28 20:33:02 GMT 2024

Powered by FUDForum. Page generated in 0.03050 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top