This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a very primitive problem

 
Moeness Baradei
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,
the file Example1.java compiles okay, but it won't run. I included the jar files in the classpath and i cant understand why it won't run.
Thanks.

code:





Error:
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Example1.class belongs to a package "net.sourceforge.jpcap.tutorial.example1". You have to run it as



That's how the .class file belonging to the package is stored and identified.
 
Moeness Baradei
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.. now i am getting this:

 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why java twice?

java java
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if you write a single java, the java command will only succeed if the .class file is in the correct directory. Is the Example1.class file in the correct directory structure?? It should be in the following directory structure

net/sourceforge/jpcap/tutorial/example1/Example1.class

This depends on how you compiled your program...
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply, where is your Example1.class file located? It should be in the folder structure/hierarchy matching with your package hierarchy as explained above.
 
Moeness Baradei
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[code]
// $Id: Example2.java,v 1.3 2002/02/18 15:33:00 pcharles Exp $

/***************************************************************************
* Copyright (C) 2001, Patrick Charles and Jonas Lehmann *
* Distributed under the Mozilla Public License *
* http://www.mozilla.org/NPL/MPL-1.1.txt *
***************************************************************************/

package net.sourceforge.jpcap.tutorial.example2;

import net.sourceforge.jpcap.capture.*;
import net.sourceforge.jpcap.net.*;


/**
* jpcap Tutorial - Example 2
*
* @author Jonas Lehmann and Patrick Charles
* @version $Revision: 1.3 $
* @lastModifiedBy $Author: pcharles $
* @lastModifiedAt $Date: 2002/02/18 15:33:00 $
*/
public class Example2
{
private static final int INFINITE = -1;
private static final int PACKET_COUNT = 10;

// BPF filter for capturing any packet
private static final String FILTER = "";

private PacketCapture m_pcap;
private String m_device;

public Example2() throws Exception {
// Step 1: Instantiate Capturing Engine
m_pcap = new PacketCapture();

// Step 2: Check for devices
m_device = m_pcap.findDevice();

// Step 3: Open Device for Capturing (requires root)
m_pcap.open(m_device, true);

// Step 4: Add a BPF Filter (see tcpdump documentation)
m_pcap.setFilter(FILTER, true);

// Step 5: Register a Listener for Raw Packets
m_pcap.addRawPacketListener(new RawPacketHandler());

// Step 6: Capture Data (max. PACKET_COUNT packets)
m_pcap.capture(PACKET_COUNT);
}

public static void main(String[] args) {
try {
Example2 example = new Example2();
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}


class RawPacketHandler implements RawPacketListener
{
private static int m_counter = 0;

public void rawPacketArrived(RawPacket data) {
m_counter++;
System.out.println("Packet " + m_counter + "\n" + data + "\n");
}
}
[/code]
 
Andre Brito
Ranch Hand
Posts: 95
Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

Is the problem solved?

If not, did you compiled the source?
 
Moeness Baradei
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Thanks
The problem is now solved.. I overcame the UnsatisfactoryLinkError by loading the DLL in the code using
System.load("jpcap.dll");

I do have a question at this point:
This is the first time that i know that java can use DLLs, does that make programs that use a dll not work in linux ?
Another thing is, can I load a JAR using the same way??

thanks a lot to everyone who answered.
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moeness Baradei wrote:This is the first time that i know that java can use DLLs, does that make programs that use a dll not work in linux ?
Another thing is, can I load a JAR using the same way??

If you are speaking of native DLLs then yes it will not work on Linux.

There is no need to load a JAR, just include it in the classpath, thats all.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic