Clad User Manual - How to Implement a Command Line Application: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 71: Line 71:
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
</pre>
</pre>
For the time being I worked around the issue by placing a src/main/resources/log4j.xml. Example: [[Simple_log4j.xml_Example|simple log4j.xml]].
</font>
</font>



Revision as of 18:00, 8 November 2016

Internal

Overview

Declare the Maven Dependency

<dependency>
    <groupId>io.novaordis.clad</groupId>
    <artifactId>novaordis-clad</artifactId>
    <version>...</version>
</dependency>

Provide an ApplicationRuntime Implementation

Extend ApplicationRuntimeBase, into a "clad" sub-package of your project. This is the recommended approach. If you need more flexibility, you can implement ApplicationRuntime interface.

The application runtime functionality is related to the following aspects:

Specify a Default Command

To provide a default command, implement public String getDefaultCommandName(). For more details on the default command, see "Default Command" section.

Define Global Options

For more details on the default command, see "Global Options" section.

Logging

Console Output

TODO


Debug Logging

TODO


SLF4J Binding

clad relies on SLF4J API, but does not enforce any binding. It is up to your application to define a binding among its dependencies. For more details see SLF4J - No StaticLoggerBinder.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.12</version>
</dependency>

TODO: Come up with a deterministic way to specify the slf4j-log4j12 version, in relation to the slf4j-api version used by clad.

Log4j

Come up with a solution for:

log4j:WARN No appenders could be found for logger (io.novaordis.clad.configuration.ConfigurationImpl).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


For the time being I worked around the issue by placing a src/main/resources/log4j.xml. Example: simple log4j.xml.

Wrapper

java -cp ... io.novaordis.clad.CommandLineApplication

Application Name

The application name should be provided as a system property argument to java, in the wrapper:


-Dapplication.name=Release



Package the application runtime implementation class and the commands in a JAR (or place them in a directory).

Set “application.name” as a system property. If the application runtime implementation class is BlueApplicationRuntime, the application.name must be “blue”.

Make sure the JAR or the directory is first on the class path (otherwise other <your-command-name>Command.class, if exist, will be instantiated first).