官术网_书友最值得收藏!

Creating a new project

Creating a new PhoneGap project is easy thanks to PhoneGap CLI. Unlike older versions of PhoneGap, where we needed to download the project template manually, we can create new projects directly from the command line. With just a single command, we can create a new project and start writing our application.

How to do it…

To create a new PhoneGap project, open your terminal or cmd. Then go to the directory where you want to maintain your source code. Run the following command:

phonegap create hello com.myapp.hello HelloWorld

It may take some time to complete the process, so be patient and let PhoneGap CLI do its magic. You will see some message during the project creation process:

How to do it…

Creating a new project progress

Congratulations! You have created your first PhoneGap project. Now, let's browse the project directory. You will see the directories as shown in the following screenshot:

How to do it…

The PhoneGap project structure

Most of the directories are empty; we will discuss the use of each directory later in the next recipe. The www/ directory is where you write code for your application. PhoneGap generated the initial starter app to work with.

How it works…

The phonegap create command is a command used to create a new project. The first argument, hello, specifies a directory for your project. Note that this directory must not exist initially; phonegap will create it for you.

The second argument, com.myapp.hello, is your application ID. The application ID is used as a unique identifier for an application. Two identical applications with different application IDs will be considered two different applications. The application ID is in reverse domain style. You can create something like com.yourdomain.applicationname.

The third argument, HelloWorld, is your application name. The application name will be used as the application's display title. This argument is optional. If you are not setting the application name, it will use the name from the first argument. If you want to change the name, you can open config.xml and edit the name element.

While we are running the phonegap create command, there are several things happening in the background:

  • The phonegap creates a new PhoneGap project with the given name and ID in the newly created directory. In our case, a PhoneGap project with the name as HelloWorld and ID as com.myapp.hello will be created under the hello directory.
  • The phonegap downloads the starter application and places it in www/ so that we can run the project directly after creating it.

    Tip

    You can use the -d option with any phonegap command to allow a verbose output. The -d option will give clear information about what is going on and the current status of the command.

主站蜘蛛池模板: 清流县| 成都市| 余干县| 张家港市| 眉山市| 方城县| 林西县| 苗栗县| 郴州市| 冀州市| 修文县| 济源市| 磐石市| 永清县| 浦城县| 墨竹工卡县| 怀柔区| 绵竹市| 临海市| 金堂县| 盈江县| 龙门县| 庄河市| 封丘县| 麻城市| 香格里拉县| 社会| 乐安县| 吐鲁番市| 凌源市| 玉环县| 六安市| 遂宁市| 吉木乃县| 台北市| 湟源县| 彭泽县| 南昌县| 夏津县| 临澧县| 开原市|