Wiki

Clone wiki

luci2 / Import Luci as your webserver and_or implement a service as a Luci module

This page shows you how to create a LUCI MODULE that can contain two things:

1. Your implementation of a SERVICE by creating a class 
   that extends luci.core.ServiceLocal
2. Luci.conf and data folder used to customize Luci with your content:
      Luci.conf
      data/
          webroot/
          404.html
  1. Create a new Maven Project:
    create a new Maven Project
  2. Once a new project is created edit the pom.xml file as follows: NOTE: since luci is not published to a maven repo yet, you need to make sure the dependencies are available in you local maven repo - by either checking out the luci projects and build them with maven, download the jars from the download section and add them to your local maven repo or add the jars to your java build path with the traditional java/eclipse means.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>yourOrganisation</groupId>
        <artifactId>yourProject</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.6</version>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>external-resources/</directory>
                                    </resource>
                                </resources>
                                <includeEmptyDirs>true</includeEmptyDirs>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
    
            <dependency>
                <groupId>org.luci</groupId>
                <artifactId>luci.core</artifactId>
                <!-- edit the version here -->
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
    
        </dependencies>
    </project>
    
  3. Create a new Service:
    newClass.jpg

  4. Your new Class should look like this (except for the comments that are added here to inform readers):

    /**
     * Your License Information
     *
     */
    package yourProject;
    
    import org.json.JSONObject;
    
    import luci.connect.Message;
    import luci.core.LcMetaJson;
    import luci.core.ServiceLocal;
    
    /**
     * 
     * @author you
     *
     */
    public class YourService extends ServiceLocal {
    
        /**Method that implements the service's logic / algorithm.
         * @return Message containing the calculated results
         * @throws Exception
         */
        @Override
        public Message implementation() throws Exception {
            // TODO Auto-generated method stub
            return null;
        }
    
        /**LcMetaJson object that describes the inputs of the service.
         * The LcMetaJSONObject is a JSONObject used by Luci to verify 
         * the inputs being sent upon a service call
         */
        @Override
        public LcMetaJson getInputDescription() {
            // TODO Auto-generated method stub
            return null;
        }
    
        /**
         * @return LcMetaJson object that describes the outputs of the service.
         */
        @Override
        public LcMetaJson getOutputDescription() {
            // TODO Auto-generated method stub
            return null;
        }
    
        /**
         * @return JSONObject that describes an example how to call this service
         */
        @Override
        public JSONObject getExampleCall() {
            // TODO Auto-generated method stub
            return null;
        }
    
    }
    
  5. When running your project make sure to select luci.core.Luci as your main class and set the working directory to yourProject/target

Updated