Skip to content

Bash embedded jar as repackaging option #1117

Closed
@aantono

Description

@aantono

When trying to run the application from a jar that has been embedded into an executable bash script, I get ClassNotFoundException: org.springframework.context.support.LiveBeansView

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/support/LiveBeansView
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:876)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:152)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:944)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:933)
    at com.example.myproject.Application.main(Application.java:14)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support.LiveBeansView
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:161)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:131)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more

When starting the application by using java -jar <jar_name> everything starts just fine.

The command to generate the executable bash is:
cat stub.sh build/libs/spring-boot-sandbox.jar > test.run

stub.sh:

#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
    java="$JAVA_HOME/bin/java"
fi
#jvm_opts=`unzip -p $MYSELF jvm.options 2>/dev/null`
#echo "Starting application using $jvm_opts"
#exec "$java" $java_args $jvm_opts -jar $MYSELF "$@"
exec "$java" $java_args -jar $MYSELF "$@"
exit 1

It seems that the problem stems with setting a custom SecurityManager

https://www.dropbox.com/s/tlo43vlqtcnh5bb/spring-boot-sandbox.jar - works fine
https://www.dropbox.com/s/dbyb1cd8yxfr3li/test.run - creates errors at startup

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions