This page provides instructions on how to use the Caplin CLI to create scaffolding for a new application.
To create a Caplin Trader 5 application, you require the following:
- A Caplin Trader development workspace. For instructions on creating a development workspace, see Creating a new workspace.
- To add support for Java Servlets in Caplin Trader's development server, you will also require:
- Java 8
- Apache Maven 3.3+
You create a package using Caplin CLI's create-app command:
caplin-cli create-app <application-name>
For example, to create a new application called MyApp, follow the steps below:
From the root directory of your development workspace, run the command below:
caplin-cli create-app MyApp
The command asks if you wish to add support for Java Servlets to the CT development server. For this example, answer no. For more information on this feature, see Adding Java Servlet support below.
The command creates the following scaffolding for your new application:
ct5-workspace/apps/MyApp/ ├── .babelrc ├── .env ├── index.html ├── package.json ├── README.md ├── scripts/ │ └── build.js ├── server/ │ └── node/ │ └── server.js ├── src/ │ ├── config/ │ │ ├── aliases.js │ │ ├── aliases-test.js │ │ └── metadata.js │ ├── example/ │ │ ├── Example.js │ │ └── __tests__/ │ │ └── ExampleTest.js │ ├── index.js │ └── index.scss └── webpack.config.js
Change directory to apps/MyApp, and run the command below to download the project's dependencies:
Caplin Trader's development server has optional support for Java Servlets. Support for Java Servlets can be activated when the application is created, or activated later through manual modification.
If your application uses Caplin's Webcentric layout manager, you need to add support for Java Servlets to the development server if you want to run the Webcentric server-side persistence Servlet in development.
Adding Java Servlet support on application creation
When you create an application using the caplin-cli create-app command, the command asks if you want to run Java Servlets during development.
If you opt to include support for Java Servlets, the caplin-cli create-app command makes the following modifications to the new application's scaffolding:
The server/node/server.js file includes code to spawn Maven to download and run Jetty:
spawn( "mvn", ["-f", "server/java/proxy-target/pom.xml", "jetty:run"], proxySpawnOptions )
An additional server/java directory is included:
server/ ├── java/ │ └── proxy-target/ │ ├── pom.xml │ ├── src/ │ │ └── main/ │ │ └── webapp/ │ │ └── WEB-INF/ │ │ ├── jetty-env.xml │ │ └── web.xml │ └── target/ │ └── tmp/ │ └── jsp └── node/ └── server.js
When you start the development server using the command npm start (see Starting the development server), the server spawns Maven to download and run Jetty. When you close the development server by pressing Ctrl-C, the Jetty server detects this and shuts down gracefully.
Adding Java Servlet support after application creation
To avoid overwriting any modifications you may make to server/node/server.js, the caplin-cli command does not include a command to add Java Servlet support to an existing application. You must activate Java Servlet support manually.
Follow the steps below:
From the root directory of your application, run the command below to install the Node.js package maven-deploy:
npm install maven-deploy
Run the command below to create the scaffolding for a new application:
caplin-cli create-app TemporaryApp
- Copy the server/java directory from the new application to your existing application.
- Compare the server/node/server.js file in the new application with the server/node/server.js file in your application. Copy the code in the new server.js that spawns Maven and paste it into the equivalent location in your application's server.js file.