<h1>Creating a Cordapp<aclass="headerlink"href="#creating-a-cordapp"title="Permalink to this headline">¶</a></h1>
<p>A Cordapp is an application that runs on the Corda platform using the platform APIs and plugin system. They are self
contained in separate JARs from the node server JAR that are created and distributed.</p>
<divclass="section"id="app-plugins">
<h2>App Plugins<aclass="headerlink"href="#app-plugins"title="Permalink to this headline">¶</a></h2>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">Currently apps are only supported for JVM languages.</p>
</div>
<p>To create an app plugin you must you must extend from <aclass="reference external"href="api/com.r3corda.core.node/-corda-plugin-registry/index.html">CordaPluginRegistry</a>. The JavaDoc contains
specific details of the implementation, but you can extend the server in the following ways:</p>
<olclass="arabic simple">
<li>Required protocols: Specify which protocols will be whitelisted for use in your web APIs.</li>
<li>Service plugins: Register your <spanclass="xref std std-ref">services</span>.</li>
<li>Web APIs: You may register your own endpoints under /api/ of the built-in web server.</li>
<li>Static web endpoints: You may register your own static serving directories for serving web content.</li>
</ol>
</div>
<divclass="section"id="services">
<h2>Services<aclass="headerlink"href="#services"title="Permalink to this headline">¶</a></h2>
<pid="id1">Services are classes which are constructed after the node has started. It is provided a <aclass="reference external"href="api/com.r3corda.node.services.api/-service-hub-internal/index.html">ServiceHubInternal</a> which
allows a richer API than the <aclass="reference external"href="api/com.r3corda.node.services.api/-service-hub/index.html">ServiceHub</a> exposed to contracts. It enables adding protocols, registering
message handlers and more. The service does not run in a separate thread, so the only entry point to the service is during
construction, where message handlers should be registered and threads started.</p>
</div>
<divclass="section"id="starting-nodes">
<h2>Starting Nodes<aclass="headerlink"href="#starting-nodes"title="Permalink to this headline">¶</a></h2>
<p>To use an app you must also have a node server. To create a node server run the gradle installTemplateNodes task.</p>
<p>This will output the node JAR to <codeclass="docutils literal"><spanclass="pre">build/libs/corda.jar</span></code> and several sample/standard
node setups to <codeclass="docutils literal"><spanclass="pre">build/nodes</span></code>. For now you can use the <codeclass="docutils literal"><spanclass="pre">build/nodes/nodea</span></code> configuration as a template.</p>
<p>Each node server by default must have a <codeclass="docutils literal"><spanclass="pre">node.conf</span></code> file in the current working directory. After first
execution of the node server there will be many other configuration and persistence files created in a node workspace directory. This is specified as the basedir property of the node.conf file, or else can be overidden using <codeclass="docutils literal"><spanclass="pre">--base-directory=<workspace></span></code>.</p>
<pclass="last">Also note that the bootstrapping process of the <codeclass="docutils literal"><spanclass="pre">corda.jar</span></code> unpacks the Corda dependencies into a temporary folder. It is therefore suggested that the CAPSULE_CACHE_DIR environment variable be set before starting the process to control this location.</p>
<h2>Installing Apps<aclass="headerlink"href="#installing-apps"title="Permalink to this headline">¶</a></h2>
<p>Once you have created your app JAR you can install it to a node by adding it to <codeclass="docutils literal"><spanclass="pre"><node_dir>/plugins/</span></code>. In this
case the <codeclass="docutils literal"><spanclass="pre">node_dir</span></code> is the location where your node server’s JAR and configuration file is.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">If the directory does not exist you can create it manually.</p>
</div>
</div>
<divclass="section"id="starting-your-node">
<h2>Starting your Node<aclass="headerlink"href="#starting-your-node"title="Permalink to this headline">¶</a></h2>
<p>Now you have a node server with your app installed, you can run it by navigating to <codeclass="docutils literal"><spanclass="pre"><node_dir></span></code> and running</p>
<blockquote>
<div>java -jar corda.jar</div></blockquote>
<p>The plugin should automatically be registered and the configuration file used.</p>
<divclass="admonition warning">
<pclass="first admonition-title">Warning</p>
<pclass="last">If your working directory is not <codeclass="docutils literal"><spanclass="pre"><node_dir></span></code> your plugins and configuration will not be used.</p>
<p>Otherwise the workspace folder for the node is created based upon the <codeclass="docutils literal"><spanclass="pre">basedir</span></code> property in the <codeclass="docutils literal"><spanclass="pre">node.conf</span></code> file and if this is relative it is applied relative to the current working path.</p>
</div>
<divclass="section"id="debugging-your-node">
<h2>Debugging your Node<aclass="headerlink"href="#debugging-your-node"title="Permalink to this headline">¶</a></h2>
<p>To enable remote debugging of the corda process use a command line such as:</p>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.