0

As questioned, how to build runnable JAR using Javalite framework? Javalite doesn't have known entry point / main class. I browse some of the examples but not found any clue.

This jar will run as stand-alone on server using java -jar command.

Below snippet of my plugin on pom.xml file

Packaging

<modelVersion>4.0.0</modelVersion>
<groupId>org.javalite</groupId>
<artifactId>activeweb-simple</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
<name>ActiveWeb Example WebApp</name>

Plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <!-- Jar file entry point -->
                <mainClass>com.company.Application</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

And the Application.java,

public class Application {
    public static void main(String[] args) throws Exception {

        String webappDirLocation = "src/main/webapp/";
        Tomcat tomcat = new Tomcat();

        String webPort = System.getenv("PORT");
        if(webPort == null || webPort.isEmpty()) {
            webPort = "8081";
        }

        tomcat.setPort(Integer.valueOf(webPort));

        StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
        System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());

        File additionWebInfClasses = new File("target/classes");
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
            additionWebInfClasses.getAbsolutePath(), "/"));
        ctx.setResources(resources);

        tomcat.start();
        tomcat.getServer().await();
    }
}

Note : I'm currently using tomcat as embedded http-server to enable the JAR file run as stand-alone. But, Javalite ActiveWeb probably has a way for this.

1 Answers1

0

You can build any number of different types of JavaLite projects, such as standalone that use some features: JavaLite HTTP, ActiveJDBC, JavaLite Async, etc. In addition, if you want to build a web application, you also will need ActiveWeb.

Here is a list of examples from the JavaLite repo:

ActiveJDBC:

ActiveWeb:

Every example app has a README file you can read to see what the example is for.

In order to start any project, just clone a repo, get it running then start modifying it to your liking.

Additionally, pay attention to the Releases page http://javalite.io/releases and keep your dependencies up to date.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46