Search code examples
javabashcordovabuild-automationapache-cordova

How to create automatically an apache cordova project via CLI through Java Command?


I'd like to create a java library that wrapps the apache cordova CLI, but unfortunately I got stuck in some Java CMD problems and I'm not quite sure where to go next.

I am able to setup everything and create the project by calling

cordova create /my/project/path/ my-project-name

This automatically creates the basic roundup, which is already a nice thing.

Unfortunatly I'm not able to continue adding platforms to the project. When calling

"/bin/bash", 
"-c", 
"cd " + path.toString(), "cordova platform add " + os

as an array of Strings, the process continues with returncode 1, but nothing is being added and it doesn't depend on the os variable in the code, because I call this once with android and ios.

I've tried the code in Terminal and bash on my Mac and it works and correctly adds the platforms.

Any suggestions?


Solution

  • The answere is fairly simple:

    "/bin/bash", 
    "-c", 
    " cd " + path.toString() + " && cordova platform add " + os
    

    If forgot to add an empty char before the cd-cmd and put everything in one line.