MalformedUrlException unbekanntes Protokoll classpath in Java
Ich versuche den Wert einer URL-Instanz-variable als classpath, aber ich erhalte die folgende Fehlermeldung:
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)
Dies ist mein 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");
}
}
Wohin gehe ich falsch?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Du schon die Antwort, die von der exception-Nachricht:
Versuchen
file://
Protokoll odergetClass().getClassLoader().getResource()
laden von Ressourcen-Verzeichnis. Andernfalls müssen Sie implementieren und registrierenURL handler
für Ihreprotocol
wenn Sie haben, es zu tun auf diese Weise.Entnehmen Sie bitte diese SO-thread für mehr info.
classpath:
ist nicht ein Protokoll. Protokoll ist in der Regelhttp://
oderftp://
(und viele andere).