Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Shell Scripts as a part of Java Project

Tags:

java

shell

cygwin

I am Executing Shell scripts in Java Using Cygwin. My Scripts are running fine at command prompt, and even if I try simple shell scripts through Java it works fine.

But now my scripts are using another shell scripts from the folder called lib So I need to include lib folder into my project.

Can any one suggest the way how to include shell script as a part of Java project.

Lib Folder-->

  • lib/lib.sh
  • lib/paxus.sh
  • lib/preload.sh
  • lib/tgzcreator.sh
  • lib/specific.sh

InSide Lib Folder these are the Shell scripts. Which my_script.sh is using.

Edit:- I want to add Shell script inside my project which uses Command line arguments and some other scripts from above folder structure.

 cmd = "D:/cygwin/bin/bash -c '/bin/my_script.sh 121 121 1212 12121'";

Help me for Doing this.

like image 529
Code Hungry Avatar asked Dec 06 '11 09:12

Code Hungry


People also ask

What is shell script in Java?

Shell Scripting is an open-source operating system. Our Shell Scripting tutorial includes all topics of Scripting executing scripting, loops, scripting parameters, shift through parameters, sourcing, getopts, case, eval, let etc.


1 Answers

If you are using maven as a build tool the best solution is to add scripts under /src/main/resources. In this case the scripts will be automatically included into your jar file, so you will be able to extract them on the fly from your java code and run.

If you want to have the scripts separately you suggested good solution. I mean lib folder. But again since I am using maven I'd put them under /src/main/sh (exactly as I put my java files under /src/main/java)

like image 58
AlexR Avatar answered Sep 30 '22 10:09

AlexR