javaresincaucho

Executing Server Jar Programatically (Caucho Resin)


I have successfully used the Caucho Resin web server and I'm considering of packaging it into a java application. They provide a jar file and code in order to start the server programatically.

Example: example/TestResin.java

package example;

import com.caucho.resin.*;

public class TestResin {

  public static void main(String []args)
  {
    ResinEmbed resin = new ResinEmbed();

    HttpEmbed http = new HttpEmbed(8080);
    resin.addPort(http);

    WebAppEmbed webApp = new WebAppEmbed("/", "/var/www/htdocs");
    resin.addWebApp(webApp);

    resin.start();
    resin.join();
  }
}

However I get the following error

java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.caucho.server.resin.EnvInit.init(EnvInit.java:49)
    at com.caucho.server.resin.EnvInit.<init>(EnvInit.java:44)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:374)
    at com.caucho.loader.Environment.initializeEnvironment(Environment.java:971)
    at com.caucho.resin.ResinEmbed.start(ResinEmbed.java:320)
    at com.mycompany.server.Resin.main(Resin.java:23)
Caused by: java.lang.ClassNotFoundException: javax.transaction.TransactionManager
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 22 more
Exception in thread "main" java.lang.NoClassDefFoundError: javax/enterprise/inject/spi/BeanManager
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.caucho.env.service.ResinSystem.<init>(ResinSystem.java:138)
    at com.caucho.env.service.ResinSystem.<init>(ResinSystem.java:99)
    at com.caucho.server.resin.Resin.<init>(Resin.java:236)
    at com.caucho.server.resin.ResinEmbedded.<init>(ResinEmbedded.java:46)
    at com.caucho.resin.ResinEmbed.start(ResinEmbed.java:322)
    at com.mycompany.server.Resin.main(Resin.java:23)
Caused by: java.lang.ClassNotFoundException: javax.enterprise.inject.spi.BeanManager
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 18 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Solution:

Added the javaee-16.jar library found inside glassfish installation directory and all works. Apparently donwloading the glassfish-api.jar from Oracle doesn't work because only methods declarations are included and no implementations.


Solution

  • Added the javaee-16.jar library found inside glassfish installation directory and all works.