Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

NoClassDefFoundError when using NetFactory

delme
2012-04-25
2013-01-21
  • delme
    delme
    2012-04-25

    Hi, I am trying to initialize a socket connection over tor using this code:

    import java.io.BufferedReader;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.net.Socket;
    import org.silvertunnel.netlib.adapter.java.JvmGlobalUtil;
    import org.silvertunnel.netlib.api.NetFactory;
    import org.silvertunnel.netlib.api.NetLayer;
    import org.silvertunnel.netlib.api.NetLayerIDs;
    public class SilverTunnelTest {
        public static void main(String[] args) {
            System.setProperty("torMinimumIdleCircuits", "3");
            System.setProperty("torMaxAllowedSetupDurationMs", "20000");
    
            JvmGlobalUtil.init();
            NetLayer netLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
            JvmGlobalUtil.setNetLayerAndNetAddressNameService(netLayer, true);
            String resp="";
            Socket so = null;
            try {
                so = new Socket("www.google.com",80);
                InputStreamReader isr =  new InputStreamReader(so.getInputStream());
                BufferedReader in = new BufferedReader(isr);
                DataOutputStream dos = new DataOutputStream(so.getOutputStream());
                PrintStream out = new PrintStream(dos);
                // send message
                out.println("GET / HTTP/1.0\n");
                out.flush();
                // receive message
                String serverMsg = "";
                while((serverMsg=in.readLine())!=null){
                    resp += serverMsg+"\n";
                }
                System.out.println("response: "+resp);
            } catch(IOException i) { i.printStackTrace(); }
            // close connection
            finally {
                try { if (so != null) so.close(); }
                catch(IOException i) { i.printStackTrace(); }
            }
    
        }
    
    }
    

    But every time the execution reaches this line

    NetLayer netLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
    

    the program crashes with these errors:

    1
    Apr 25, 2012 5:12:05 PM org.silvertunnel.netlib.api.service.NetlibVersion <init>
    INFO: Welcome to silvertunnel.org Netlib (version 0.13-beta)
    Apr 25, 2012 5:12:05 PM org.silvertunnel.netlib.api.NetFactory registerNetLayer
    INFO: registerNetLayer with netLayerId=tcpip
    Apr 25, 2012 5:12:05 PM org.silvertunnel.netlib.api.NetFactory registerNetLayer
    INFO: registerNetLayer with netLayerId=tls_over_tcpip
    Apr 25, 2012 5:12:05 PM org.silvertunnel.netlib.util.TempfileStringStorage <clinit>
    INFO: TempfileStringStorage directory=/var/folders/uW/uWQ+KN01Fly3V5JCBOXL6k+++TI/-Tmp-/
    Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
    at org.silvertunnel.netlib.layer.tor.TorNetLayer.<init>(TorNetLayer.java:87)
    at org.silvertunnel.netlib.layer.tor.TorNetLayerFactory.getNetLayerById(TorNetLayerFactory.java:61)
    at org.silvertunnel.netlib.api.NetFactory.getNetLayerById(NetFactory.java:63)
    at SilverTunnelTest.main(SilverTunnelTest.java:19)
    Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    … 4 more

    Has anyone else experienced the same thing? What is causing this?

     
  • delme
    delme
    2012-04-25

    Hi,

    Thanks for the reply, you were right, I hadn't added the bcprov-jdk15-145.jar to to the build path.

    Cheers,
    Brenton