8000 Set plugins.dir more robustly · imagej/example-legacy-plugin@cc6959c · GitHub
[go: up one dir, main page]

Skip to content

Commit cc6959c

Browse files
committed
Set plugins.dir more robustly
This avoids problems with spaces and other special characters in the directory name. Closes #7.
1 parent 152fabe commit cc6959c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/com/mycompany/imagej/Process_Pixels.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ public void showAbout() {
168168
*
169169
* @param args unused
170170
*/
171-
public static void main(String[] args) {
171+
public static void main(String[] args) throws Exception {
172172
// set the plugins.dir property to make the plugin appear in the Plugins menu
173+
// see: https://stackoverflow.com/a/7060464/1207769
173174
Class<?> clazz = Process_Pixels.class;
174-
String url = clazz.getResource("/" + clazz.getName().replace('.', '/') + ".class").toString();
175-
String pluginsDir = url.substring("file:".length(), url.length() - clazz.getName().length() - ".class".length());
176-
System.setProperty("plugins.dir", pluginsDir);
175+
java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
176+
java.io.File file = new java.io.File(url.toURI());
177+
System.setProperty("plugins.dir", file.getAbsolutePath());
177178

178179
// start ImageJ
179180
new ImageJ();

0 commit comments

Comments
 (0)
0