I am trying to make a customized IntelliJ plugin and run a shell script file stored in src/main/resources
folder from a java code file in the main folder.
I need Help with a way to execute and change the contents of files in the resources folder using configured paths.
Tried these ways so far
//Method - 1
String filePath = getClass().getClassLoader().getResource("file.sh").getPath();
System.out.println(filePath);
String[] paths = filePath.split(":");
System.out.println(paths[1]);
//Method-2
URL res = getClass().getClassLoader().getResource("file.sh");
File script = null;
try {
assert res != null;
script = Paths.get(res.toURI()).toFile();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
String absolutePath = script.getAbsolutePath();
//Method-3
final ClassLoader classLoader = getClass().getClassLoader();
final File script = new File(classLoader.getResource("file.sh").getFile());
System.out.println(script.getPath());
But all these lead to a path file:/Users/username/projects/projectname/build/idea-sandbox/plugins/project-name/lib/Project-Name-1.0-SNAPSHOT.jar!/file.sh