-1

I am trying set the value of a URL instance variable as the classpath but I am getting the below error:

Exception in thread "main" java.net.MalformedURLException: unknown protocol: classpath
    at java.net.URL.<init>(URL.java:600)
    at java.net.URL.<init>(URL.java:490)
    at java.net.URL.<init>(URL.java:439)
    at com.foodprocessor.App.main(App.java:18)
C:\Users\admin\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

This is my code:

    public class App {
    public static void main(String[] args) throws MalformedURLException{
        MyEnvironmentA env = new MyEnvironmentA(new URL("classpath:"+System.getProperty("java.class.path")));
        env.run("ChocolateMilk");
     }
   }

Where am I going wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sumanth Jois
  • 3,146
  • 4
  • 27
  • 42

2 Answers2

0

You already got the answer from the exception message:

unknown protocol: classpath

Try to use file:// protocol or getClass().getClassLoader().getResource() to load resource directory. Otherwise you need to implement and register URL handler for your protocol if you have to do it this way.

Please refer to this SO thread for more info.

Community
  • 1
  • 1
shizhz
  • 11,715
  • 3
  • 39
  • 49
-4

classpath: isn't a protocol. Protocol is usually http:// or ftp:// (and lots of others).

Steve Smith
  • 2,244
  • 2
  • 18
  • 22