I’m trying to execute these commands inside a web service (jersey 2):
cmd /c cd FOLDER
&&
mvn archetype:generate
-DarchetypeGroupId=com.hybris.datahub
-DarchetypeArtifactId=datahub-extension-archetype
-DarchetypeVersion=ARCHETYPEVERSION
-DsdkVersion=SDKVERSION
-DgroupId=XXX.XXX.XXX
-DartifactId=AZERTY
-Dversion=VERSION
-DinteractiveMode=false
And after it finish, I change what I need to change then I execute these commands:
cmd /c cd FOLDER/AZERTY
&&
mvn clean install
Method that executes these commands:
private String executeCommand(String command) {
try {
ArrayList<String> result = new ArrayList<>();
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while((line = reader.readLine())!= null)
if(line.contains("BUILD"))
result.add(line.substring(7));
for(int i=0; i<result.size(); i++)
if(result.get(i).equals("BUILD FAILURE"))
return "BUILD FAILURE";
return "BUILD SUCCESS";
} catch(IOException | InterruptedException e) {
return null;
}
}
I’m using Tomcat 7 as a server.
My problem that this command executes half of the time and don't finish to the end and I read in an article that we can use org.apache.maven
to create a Maven project and deploy it programmatically but I didn’t find an example.
Please help me what I need to do (sorry for my english ^^”)