Question

I'm trying to check some SNMP example, so

  • i've downloaded snmp4j.jar
  • compiled SNMP.java using javac -cp snmp4j.jar SNMP.java (it's OK)
  • tried to start it using java -cp snmp4j.jar SNMP, but

it reports:

root@comp:~/workspace_c/SNMP# java -cp snmp4j.jar SNMP
Exception in thread "main" java.lang.NoClassDefFoundError: SNMP
Caused by: java.lang.ClassNotFoundException: SNMP
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: SNMP.  Program will exit.

UPDATE: And when I import snmp4j.jar to the java project, it works normally in ECLIPSE...

UPDATE@2: main part of SNMP.java

import org.snmp4j.CommunityTarget;
...
public class SNMP {
  public static void main(String[] args) {
  ...
  }
}

what i'm doing wrong? it's first time i've met snmp4j so i know noting about it

Was it helpful?

Solution

If I understand correctly, SNMP is your example class, which isn't inside the jar. In that case, you need to add to the classpath both the jar and your current directory:

java -cp .:snmp4j.jar SNMP

OTHER TIPS

As far as I can see you are trying to run your application with SNMP4J.jar (upper case) but when you compiled your application you probably used lower case version. Your prompt shows that your are using unix OS that has case sensitive file system. So, check the case of the JAR file name. I believe that all letters are in lower case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top