where to store the script file in my application
Your wrote, I can interpret this as:
- Storing file contents in memory
- Saving a file in a
.jar file
I think you mean the second.
You can put it in your jar file in every folder you need. I prefer a subfolder (rather than a root)
First put the file in your jar. Then you have to extract it to a temporary file (see Link if you want to know how to create a temporary file).
Then create an input stream from a file in your bank and copy the data to a temp file.
InputStream is = getClass().getResourceAsStream("/path/script.sh"); OutputStream os = new FileOutputStream(tempFile); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } buffer = null;
Then you must execute your shellscript
Runtime.getRuntime().exec("terminalname " + tempFile.getAbsolutePath());
Perhaps you can use this line to execute the script (I don't think this will work with your parameters):
java.awt.Desktop.getDestkop().open(tempFile);
Hope this answers your question.
source share