Hi i have a shell script named script .sh that create maven project having parent pom and multiple modules under it as follows:

 #!/bin/bash 
 mvn archetype:generate -DgroupId="com.low.co" -DartifactId="tool-release" -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=pom-root -DarchetypeVersion=RELEASE
cd yeti-release
 mvn archetype:generate -DgroupId="com.low.cp" -DartifactId="tool-api" -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE
 mvn archetype:generate -DgroupId="com.low.cp" -DartifactId="tool-impl" -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE
 mvn archetype:generate -DgroupId="com.low.cp" -DartifactId="tool-rest" -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE
 mvn archetype:generate -DgroupId="com.low.cp" -DartifactId="tool-service" -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE 

I want to run this script from java code i am using mac osx i tried every thing my code that is opening this script is as follows:

   final File scriptDirectory = new File("src/main/resources/");  
   final String shellScript = "./script.sh"; 
   ProcessBuilder pb = new ProcessBuilder();
   pb.command("/bin/bash","-e",shellScript);
   pb.directory(scriptDirectory); 
   p=pb.start();

when i change script.sh it is not showing console nor executing any of the commands in the shell script
any suggestions pls

A stab in the dark here, but have you tried using RunTime instead? I think you can accomplish the same by (please note that the syntax may be off):

Runtime.getRuntime().exec("/bin/bash -e " + shellscript);

More info HERE.

Edited 7 Months Ago by RudyM

This article has been dead for over six months. Start a new discussion instead.