Command-line tools for Codename One
Project Status: This project is at a very early stage. If you want to get started with Codename One, building cross-platform mobile apps in Java, I recommend you start with the official Codename One Getting Started Tutorial. Once you are familiar with the toolkit, you may want to revisit this command-line tool as it aims to boost development productivity, especially for developers who are comfortable with the command-line.
- Create new Codename One projects for Netbeans, Eclipse, or IntelliJ
- Use any existing CN1 project as a template.
- Select existing template from GUI template browser
- Run templates in Codename One simulator
- Run Codename One apps in the CN1 simulator
- Easily build and distribute your CN1 applications directly from the command-line
- Open Codename One settings for projects from the command-line
- NodeJS - Only used for distribution of the tool via NPM
npm install -g codenameone-cli
sudo npm install -g codenameone-cli
NOTE: The above commands will install it globally, and you require admin permissions to do this typically (hence the
sudo in the linux/mac command). You can also install it locally, using
npm install codenameone-cli in which case the command will be installed at
Usage: codenameone-cli [command] Commands: create - Create a new Codename One Project settings - Open project settings for project in current directory. css - CSS-related commands test - Unit-test related commands install-jars - Install latest jars into project install-tests - Install tests.xml file with some test targets install-appium-tests - Install appium.xml file with some appium tests defined. git-init - Same as git init, but adds suitable .gitignore file. git-clone - Same as git clone, but installs jars.
cn1 create <dest-dir> <package-id> <main-class-name> [-i Netbeans|Eclipse|IntelliJ] [-t http://example.com/project/template.zip]
Creating a basic project in directory named "helloworld":
cn1 create helloworld com.mycompany.hello HelloWorld
Follow the prompt for the other details (e.g. package id, main class, IDE, template, etc...)
Using the GUI "create project wizard" ... Just add
cn1 create helloworld -g
This will open a GUI form that allows you to browse and select a template to use for the project.
You can click on any of the templates, and get more details about it, or run the template inside the Codename One simulator directly.
Specifying Template and IDE in Command-line
cn1 create helloworld com.mycompany.hello HelloWorld \ -i Netbeans \ -t https://github.com/codenameone/SQLSample/archive/master.zip
Opening Project Settings
Navigate to any Codename One project directory, and type:
This will open the Codeame One settings app so you can configure your project (e.g. add cn1libs, set up iOS signing, add build-hints etc..
Contributing Application Templates
The templates listed in the "Create Project Form" are all loaded from this json file hosted on Github. To add your own templates, you can simply fork the codenameone-templates project, and add your template to that JSON file. Then issue a pull request. We'll review it and merge it if appropriate.
Of course, templates don't need to be listed there to be available for use. If your Codename One project is on Github, you can simply provide the "master.zip" URL as the
-t parameter of
cn1 create and the template will be used.
Cloning Projects From github
Generally, when we host Codename One projects on Github, we strip out the common binaries like CodenameOne.jar, JavaSE.jar, etc... This can be a little annoying when you are cloning projects because you have to first copy the jar files back into the project before you can build it. The
cn1 git-clone command is a thin wrapper around
git clone that will automatically perform this housekeeping for you.
Let's take the KitchenSink project, for example.
$ cn1 git-clone https://github.com/codenameone/KitchenSink Cloning into 'KitchenSink'... Installing jars into KitchenSink... Downloading 11606508 bytes Download completed! Project ready at KitchenSink
NOTE: It also works to specify only the project using "ownername/projectname", e.g.
cn1 git-clone codenameone/KitchenSink
Now we can immediately build this project:
$ cd KitchenSink $ ant jar
Or run it in the Codename One simulator:
$ ant run
Bonus Points: You can clone and run the project in a single line with:
$ cn1 git-clone https://github.com/codenameone/KitchenSink && cd KitchenSink && ant run
Finding Projects To clone
list-demos command to find Codename One projects that can be cloned using the
$ cn1 list-demos
You'll get a readout like:
shannah/GeoVizDemo : A demo app using the Codename One GeoViz Library
Adding Your Own Demos
list-demos command lists all projects on Github that are tagged with both the
demo topics. If you have a demo project that you are hosting on Github, all you need to do is add these topics to your project, and your project will be returned by the