I have get this exception. but this exception is not reproduced again. I want to get the cause of this
Exception Caught while Checking tag in XMLjava.net.UR
I ran into this problem because my path had white space.
Once I removed the white space in the file path it worked for me.
Caused by: java.net.URISyntaxException: Illegal character in path at index 45: file:/var/lib/jenkins/workspace/Engine Release/target/classes/com/app/model/script/ScriptEngineScript.class
at java.net.URI$Parser.fail(URI.java:2848) ~[?:1.8.0_191]
at java.net.URI$Parser.checkChars(URI.java:3021) ~[?:1.8.0_191]
at java.net.URI$Parser.parseHierarchical(URI.java:3105) ~[?:1.8.0_191]
at java.net.URI$Parser.parse(URI.java:3053) ~[?:1.8.0_191]
at java.net.URI.<init>(URI.java:588) ~[?:1.8.0_191]
at java.net.URL.toURI(URL.java:946) ~[?:1.8.0_191]
at org.codehaus.groovy.ast.decompiled.AsmDecompiler.parseClass(AsmDecompiler.java:70) ~[groovy-2.5.11.jar:2.5.11]
It needs a complete uri with type/protocol e.g
file:/C:/Users/Sumit/Desktop/s%20folder/SAMPLETEXT.txt
File file = new File("C:/Users/Sumit/Desktop/s folder/SAMPLETEXT.txt");
file.toURI();//This will return the same string for you.
I will rather use direct string to avoid creating extra file object.
I had the same "opaque" error while passing a URI on the command line to a script. This was on windows. I had to use forward slashes, NOT backslashes. This resolved it for me.
You must have the string like so:
String windowsPath = file:/C:/Users/sizu/myFile.txt;
URI uri = new URI(windowsPath);
File file = new File(uri);
Usually, people do something like this:
String windowsPath = file:C:/Users/sizu/myFile.txt;
URI uri = new URI(windowsPath);
File file = new File(uri);
or something like this:
String windowsPath = file:C:\Users\sizu\myFile.txt;
URI uri = new URI(windowsPath);
File file = new File(uri);
The root cause for this is file path contains the forward slashes instead of backward slashes in windows.
Try like this to resolve the problem:
"file:" + string.replace("\\", "/");
A valid URI does not contain backslashes, and if it contains a :
then the characters before the first :
must be a "protocol".
Basically "C:\Documents and Settings\All Users\.SF\config\sd.xml"
is a pathname, and not a valid URI.
If you want to turn a pathname into a "file:" URI, then do the following:
File f = new File("C:\Documents and Settings\All Users\.SF\config\sd.xml");
URI u = f.toURI();
This is the simplest, and most reliable and portable way to turn a pathname into a valid URI in Java. It should work on Windows, Mac, Linux and any other platform that supports Java. (Other solutions that involve using string bashing on a pathname are not portable.)
But you need to realize that "file:" URIs have a number of caveats, as described in the javadocs for the File.toURI() method. For example, a "file:" URI created on one machine usually denotes a different resource (or no resource at all) on another machine.