As a follow-up to our recent announcement about transitioning to Maven, this post provides an overview of the new project structure. Jump To Topic Tip If you want to follow along with this tutorial, you can quickly generate a new project using Codename One intializr. The new project structure is based on the cn1app-archetype. You can […]
2. It comes bundled with a maven wrapper script, and utility shell (and bat) scripts to facility command-line usage.
3. The includes NetBeans and IntelliJ configuration files to provide better integration with those IDEs.
4. The “common” module contains all of the cross-platform stuff, and is the most direct successor to the old Ant project structure.
ii. CSS files are in common/src/main/css.
iii. Java files are in common/src/main/java.
iv. Resources are in common/src/main/resources.
v. Kotlin files are in common/src/main/kotlin.
vi. GUIBuilder files are in common/src/main/guibuilder.
vii. Unit tests are in common/src/test/java.
6. You can install cn1lib dependencies either via a Maven <dependency> snippet in your common/pom.xml file, or using Codename One Settings. You can Also use the install-cn1lib goal.
Let’s now go through each module in the project and discuss its purpose.
A Codename One application. All of your cross-platform application code goes in this module.
Module containing native Android code such as native interface implementations.
Module containing native iOS code, such as native interface implementations.
Module containing native JavaSE code, such as native interface implementations.
Module containing native Windows UWP code for the UWP windows port.
Module where legacy cn1libs will be installed the cn1:install-cn1lib goal.
The archetype project includes run.sh and build.sh shell scripts, as well as their Windows counterparts run.bat and build.bat. These scripts are convenience wrappers for common commands that you may wish to perform on the Command-line. e.g.
./build.sh ios_source # project will be generated in ios/target directory
./build.sh android_source # project will be generated in android/target directory.
By default, only the “common” module is activated. You can activate other modules by specifying them with the codename1.platform property. e.g. If you wanted to build the javase module, you would do:
mvn package -Dcodename1.platform=javase
If, instead, you wanted to build for iOS, you would do:
mvn package -Dcodename1.platform=ios
e.g. To build a Mac Desktop app you would run:
mvn package -Dcodename1.platform=javase -Dcodename1.buildTarget=mac-os-x-desktop
And to build for Windows Desktop, you would run:
mvn package -Dcodename1.platform=javase -Dcodename1.buildTarget=windows-desktop
If you know a clever solution to this issue, I’m all ears. My solution was to just provide the build.sh and build.bat scripts to wrap the common goals and include the needed properties at that level.
Check out the build.sh script source for a list of the most-common build commands.
As mentioned above, we’ve done some work to add better integration than default to IntelliJ and NetBeans. If you open the project in IntelliJ, the Configuration menu will include options for all of the common commands including building the project for each target platform, running in the simulator, opening Codename Settings, and updating Codename One.
NetBeans includes similar support, and we plan to add “special” support for Eclipse and VSCode in the near future.
See Getting Started with the Bare-bones Java App Project for more in-depth coverage of each IDE including screenshots.
Our Maven support represents months of careful work, and there is much more that could be discussed. Over the coming weeks I’ll be writing more blog posts on various aspects of this support. In the mean time, you can check out the Getting Started tutorial and the Codename One Maven Developer Guide for a deeper dive.
Source: CodeName One