1

Using maven-assembly-plugin I could bundle my java web application into a single standalone.jar

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>my.package.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>standalone</finalName>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </plugin>

using the command

$ mvn clean compile assembly:single

The application is a REST back-end based on grizzly and jersey. I can start it using

$ java -jar standalone.jar

and it seems to work. The console output tells me that the HTTP server has started and is now listening on port 8765.

Unfortunately when I send a request to any of the REST endpoints I receive a response with error code 500 Internal Server Error. As I can conclude from the output, none of the request handling methods are called.

The application works correctly if it is started from within the IDE IntelliJ (by pressing the run button).

A similar questions was asked Java JAR behaving differently to program run out of IDE but in my case the flag -Dfile.encoding=UTF-8 which is also set by the IDE does not solve the problem

EDIT

As suggested in the comments, I have tried to inspect the log output. I was following the approach described in Grizzly Standalone Logging

When I run the application from the IDE with the finest logging level I receive a lot of additional messages including an an exception

Dez 03, 2016 11:36:07 PM org.glassfish.jersey.internal.util.ReflectionHelper$2 run
FINER: Unable to load class org.osgi.framework.BundleReference using the current class loader.
java.lang.ClassNotFoundException: org.osgi.framework.BundleReference
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.glassfish.jersey.internal.util.ReflectionHelper$2.run(ReflectionHelper.java:262)
    at org.glassfish.jersey.internal.util.ReflectionHelper$2.run(ReflectionHelper.java:247)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.glassfish.jersey.internal.util.ReflectionHelper.<clinit>(ReflectionHelper.java:1471)
    at org.glassfish.jersey.server.ResourceConfig$State.<init>(ResourceConfig.java:112)
    at org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:353)
    at my.package.Main.main(Main.java:42)

I do not get any additional logging messages when I execute the standalone.jar with -Djava.util.logging.config.file=...

Community
  • 1
  • 1
JCvanDamme
  • 621
  • 5
  • 20
  • There should be something about the errors in the log files for the server. Have you looked? If yes and there was nothing, have you tried increasing the logging level? – Stephen C Dec 03 '16 at 22:07

1 Answers1

0

I doubt your jar has been packaged with all the required dependecies packaged within it. Check first if the causing class org.osgi.framework.BundleReference is actually included into your jar.

If not, I imagine there's something missing in your pom. Include a simple goal execution to your assembly plugin definition and run Maven again:

  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        ...
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id> <!-- this is used for inheritance merges -->
        <phase>package</phase> <!-- bind to the packaging phase -->
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

See documentation.

Little Santi
  • 8,563
  • 2
  • 18
  • 46