Long path tool .jar java
Then, I chanced upon an article and with a little bit of tweaking, I was able to get it working. Well, I visited the plugin’s home page and after struggling for 3 hrs, I was none the wiser.
It was complaining that the path was too long! bat file that is generated by the appassembler, suddenly wont launch. I am using the Maven appassembler plugin to create a deployable distribution for my Rmi Server. * IllegalArgumentException if the URL does not correspond to a file.Windows sucks! We all know that. Public static URL getLocation(final Class c) * FileUtils#urlToFile(URL) to convert the result to a File}. * path to the JAR (e.g., "file:/path/to/my-jar.jar"). * "/path/to/my-jar.jar!/my/package/M圜lass.class") then it will return the * If the class is within a JAR file (e.g., * "/path/to/my/package/M圜lass.class") then it will return the base directory * If the class is directly on the file system (e.g., * Gets the base location of the given class. To achieve these steps, you might have methods like the following: /** However, if your file path has other non-alphameric characters such as + you will have problems with URLDecoder mangling your file path. And if your file path has spaces encoded as %20, this approach may appear to work.
In practice, URLDecoder generally does not throw IllegalArgumentException as threatened above. Which approach the decoder takes is left to the implementation. It could either leave illegal characters alone or it could throw an IllegalArgumentException. There are two possible ways in which this decoder could deal with illegal strings. The character "%" is allowed but is interpreted as the start of a special escaped sequence. It is assumed that all characters in the encoded string are one of the following: "a" through "z", "A" through "Z", "0" through "9", and "-", "_", ".", and "*". Some characters of the URL, : and / in particular, are not valid URL-encoded characters. Lastly, I would highly discourage using URLDecoder.
#Long path tool .jar java full
This is its own challenge see Kohsuke Kawaguchi's blog post about it for full details, but in short, you can use new File(url.toURI()) as long as the URL is completely well-formed. Step 2: URL to FileĮither way, once you have a URL, the next step is convert to a File. So I recommend the #2 invocation shown above instead, as it seems safer. Note that both getResource("") and getResource(".") failed in my tests, when the class resided within a JAR file both invocations returned null. Conversely, the getProtectionDomain approach correctly yields a file: URL even from within OSGi. It may be a file: path, but it could also be jar:file: or even something nastier like bundleresource://346.fwk2106232034:4/foo/Bar.class when executing within an OSGi framework. The getResource approach yields the full URL resource path of the class, from which you will need to perform additional string manipulation. However, it is possible that the Java runtime's security policy will throw SecurityException when calling getProtectionDomain(), so if your application needs to run in a variety of environments, it is best to test in all of them. The getProtectionDomain approach yields the base location of the class (e.g., the containing JAR file).
URL url = ().getCodeSource().getLocation() Step 1: Class to URLĪs discussed in other answers, there are two major ways to find a URL relevant to a Class. Once you have the File, you can call getParentFile to get the containing folder, if that is what you need. It is important to understand both steps, and not conflate them. To obtain the File for a given Class, there are two steps: