Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

URI not Hierarchical

807601May 23 2008 — edited May 24 2008
What is it that makes a URI hierarchical or not?

I've been trying to list the classes in a package called rainfallSeriesTranslatorMethods using platform independent code. I'm creating a file object from the URI of the package. Here's the summarised code...
	
        private String fileExt 			= MethodsRegister.CLASS_FILE_EXTENSION;
	private String anonymousFlag 	= MethodsRegister.ANONYMOUS_INNER_CLASS_FLAG;
	private URI dirURI;

        ...

	dirURI = getURI();

        ...

	private URI getURI() {
		try {
			dirURI = Launcher.class.getResource("/" + pckgname).toURI();
			} catch (URISyntaxException e) {
				System.out.println("RainfallSeriesTranslator.src.ui.Launcher cannot find the resource '" + pckgname + "'.");
				e.printStackTrace();
				}
		return dirURI;
		}
      }
  
        ...

	        String[] files = dir.list();
  	        for (String file : files) {
  	        	//Iterate through all files and select files ending with the right extension 
  	        	if (file.endsWith(fileExt)){
  	        		//Don't include anonymous classes
  	        		if (!file.contains(anonymousFlag)){
  	        			methodsArrayList.add(file.replace(fileExt, ""));
  	        			}
  	        		}
  	        	}
This works well before compiling into a .Jar, but it fails when the code is compiled into a .Jar with the following...

ExceptionInInitializerError
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
	at java.io.File.<init>(File.java:335)
	at rainfallSeriesTranslator.MethodsRegister.<init>(MethodsRegister.java:18)
If I print out the URI from the 'not-within-jar' code I get..
file:/Users/Shared/PERRMOSS/bin/rainfallSeriesTranslatorMethods
and if I print the URI from the 'within-jar' code I get...
jar:file:/Users/Shared/PERRMOSS.jar!/rainfallSeriesTranslatorMethods
According to the error message, the second example is not hierarchical. Can anyone explain why?

Is there a way to fix up the non-hierarchical URI, such as removing the "jar:" prepend?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2008
Added on May 23 2008
2 comments
632 views