473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error on SNMP Java Client Application

sreekandank
I have written the following SNMP client code to display the hardware information
Expand|Select|Wrap|Line Numbers
  1. import java.io.IOException;
  2. import org.snmp4j.CommunityTarget;
  3. import org.snmp4j.PDU;
  4. import org.snmp4j.Snmp;
  5. import org.snmp4j.Target;
  6. import org.snmp4j.TransportMapping;
  7. import org.snmp4j.event.ResponseEvent;
  8. import org.snmp4j.mp.SnmpConstants;
  9. import org.snmp4j.smi.Address;
  10. import org.snmp4j.smi.GenericAddress;
  11. import org.snmp4j.smi.OID;
  12. import org.snmp4j.smi.OctetString;
  13. import org.snmp4j.smi.VariableBinding;
  14. import org.snmp4j.transport.DefaultUdpTransportMapping;
  15. public class SNMPManager
  16. {
  17.  Snmp snmp=null;
  18.  String address=null;
  19.  public SNMPManager(String add)
  20.  {
  21.   address=add;
  22.  }
  23.  public static void main(String[] args)throws IOException
  24.  {
  25.   SNMPManager client=new SNMPManager("udp:127.0.0.1/161");
  26.   client.start();
  27.   String sysDescr=client.getAsString(new OID(".1.3.6.1.2.1.1.1.0"));
  28.   System.out.println(sysDescr);
  29.  }
  30.  private void start()throws IOException
  31.  {
  32.   TransportMapping transport=new DefaultUdpTransportMapping();
  33.   snmp = new Snmp(transport);
  34.   transport.listen();
  35.  }
  36.  public String getAsString(OID oid)throws IOException
  37.  {
  38.   ResponseEvent event=get(new OID[]{oid});
  39.   return event.getResponse().get(0).getVariable().toString();
  40.  }
  41.  public ResponseEvent get(OID oids[])throws IOException
  42.  {
  43.   PDU pdu=new PDU();
  44.   for(OID oid:oids)
  45.   {
  46.    pdu.add(new VariableBinding(oid));
  47.   }
  48.   pdu.setType(PDU.GET);
  49.   ResponseEvent event=snmp.send(pdu, getTarget(),null);
  50.   if(event != null)
  51.   {
  52.    return event;
  53.   }
  54.   throw new RuntimeException("GET timed out");
  55.  }
  56.  private Target getTarget()
  57.  {
  58.   Address targetAddress=GenericAddress.parse(address);
  59.   CommunityTarget target=new CommunityTarget();
  60.   target.setCommunity(new OctetString("public"));
  61.   target.setAddress(targetAddress);
  62.   target.setRetries(2);
  63.   target.setTimeout(1500);
  64.   target.setVersion(SnmpConstants.version2c);
  65.   return target;
  66.  }
  67. }
  68.  
When I run this program, that shows the exception as given below:

Exception in thread "main" java.lang.NoClassDefFoundError: org/snmp4j/TransportMapping
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.ja va:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at sun.launcher.LauncherHelper.getMainMethod(Launcher Helper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:486)

Caused by: java.lang.ClassNotFoundException: org.snmp4j.TransportMapping
at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
... 6 more


Please help me to correct this error. Thanks in advance...
Mar 26 '16 #1
1 4101
Did you add the jar SNMP4J to WEB-INF/lib?
Jun 15 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Paul Hutchinson | last post by:
All, I wonder if anyone can help/advise with the following interoperability issue we are encountering? We have a .NET web service that takes an abstract type as parameter. Using it from a...
0
by: AlokSingh | last post by:
hi, I need to communicate between a COM server and a Java Client application. The need is to transfer a formatted array of string. The Solution should be somewhat DDE based architecture. Any...
7
by: David Laub | last post by:
I've also posted this issue to a Sun/java formum, but since it appears to be an integration issue, this may be the better place to posr: I have written a dot net/c# Web Services doesn't fully...
1
by: Vaibhav Modak | last post by:
Hi All, I have a Web Service written in Java (Web Logic) and I am trying to call it in my ASP. NET client. I am facing a problem while getting the data from the Web Service Method. My Web...
0
by: vijayalakshmi.venkataraman | last post by:
Hello, I have a .NET client that accesses a Java webservice. Let me first say that the client stub I got generated from the wsdl was incomplete and had to make changes to it manually to make it...
2
by: Tim Murray | last post by:
First of all, I don't know much about Java, even its naming and version numbering nomenclature, and second, if there is a better group to ask this in, please let me know. System is Mac with...
1
by: Sebitti | last post by:
I'm getting timeout error in my client application (asp.net client) when I call a web service that is taking some time (2 - 3 minutes). How can I configure the timeout limit? Current...
0
by: f.reuter | last post by:
I am fully in 'interoperability' I am coding soap server and client application and i'm testing java (AXIS)versus .net. When java client calls .net server Fx 2 on IIS 6,windows 2003, i hav the...
2
jeffbroodwar
by: jeffbroodwar | last post by:
i'm currently working on a project about webservices. i tried to create an ordinary service that inserts data to the database. here's the code : ===================================================...
3
by: TsanChung | last post by:
I want to make a java TCP socket client to communicate with a TCP server socket on linux. Are there some sample C unix server and java client socket programs available? The Richard Stevens'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.