Most developers use light-codegen as a Java command line tool or Docker command line
tool to scaffold their project. There is another option that is still working in progress
which you can utilize a service from light-portal to generate the code from the specification
defined in marketplace.
There are two parts for the light-codegen in light-portal: an API built with light-hybrid-4j
and a single page application built with React.
The following tutorial focuses on how to start the light-port/hybrid-query server with code
generator API embedded.
In order to complete this tutorial, you need to clone the following repository into your
workspace. The following assumes networknt as workspace folder under user home directory.
The configuration files are located at light-config-test/light-portal/hybrid-query/cloud
folder and you need to go to that folder to start the server.
First let’s build light-codegen so that we can have all the jar files locally. As light-codegen
are released to maven central, you can download the right version of jar files from there as
mvn clean install -DskipTests
Now let’s build the hybrid-query server in light-portal.
mvn clean install
Start server with service dependencies in pom.xml
By default, hybrid-query project pom.xml include all the dependencies for codegen-web. The
following block can be found in pom.xml file.
<!-- light-codegen dependencies can be removed and put the jar file into service folder. -->
In this case, the jar files for light-codegen is loaded form maven central when the project
Now let’s copy the codegen-web jar file to ~/networknt/light-config-test/light-portal/hybrid-query/service
cp ~/networknt/light-codegen/codegen-web/target/codegen-web-1.5.11.jar .
Note that this service jar must be copied to service folder in order to load and merge schema
file with other services on the same server.
To start the server, let’s use the externalized config files in light-config-test folder.
java -Dlight-4j-config-dir=./config -Dlogback.configurationFile=./logback.xml -cp ~/networknt/light-portal/hybrid-query/target/hybrid-query-1.0.0.jar:../service/* com.networknt.server.Server
Once the server is up and running, you can follow the step below Test Codegen Service to
confirm it is working.
Start server with dependencies in service folder
Putting dependent services into hybrid-query pom.xml file is one way to embed services but
it is not flexible as you have to rebuild the project in order to change the version of
services. Another way is to add these dependent jar files into a service folder and then
load dynamically during server startup by putting these files into the classpath. In this
way, if you want to upgrade your services, you just need to copy the new version of jar
files into the service folder and restart the hybrid-query server.
In summary, it makes sense to include the dependencies into pom.xml during development as
it is very convenient. However, when you goto production, it is wise to put these services
into a separate folder to load them dynamically.
Now let’s first copy the jar files to ~/networknt/light-config-test/light-portal/hybrid-query/service
folder from just built light-codegen project.