I am working on a side project using Spring Boot, Jython and Pygments with Maven and am getting an odd error when trying to launch the application after the Maven packaging step.
Launching within the IDE (Eclipse Luna) as well as when using mvn spring-boot:run has worked successfully during the initial development process.
After creating the executable jar using the spring-boot-maven-plugin, navigating to the resulting target directory and launching with java -jar app-0.0.1.jar - I am seeing the error:
2015-12-07 16:05:11.131 INFO 6890 --- [ main] app.Application : Starting Application v0.0.1 on localhost with PID 6890 (/Users/me/Code/EclipseWorkspaces/app/app-0.0.1.jar started by me in /Users/me/Code/EclipseWorkspaces/app/target)
2015-12-07 16:05:11.135 INFO 6890 --- [ main] app.Application : No profiles are active
2015-12-07 16:05:12.418 INFO 6890 --- [ main] org.eclipse.jetty.server.Server : jetty-9.2.14.v20151106
2015-12-07 16:05:12.489 INFO 6890 --- [ main] application : Initializing Spring embedded WebApplicationContext
2015-12-07 16:05:12.970 INFO 6890 --- [ main] org.eclipse.jetty.server.Server : Started @2685ms
2015-12-07 16:05:14.536 WARN 6890 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'syntaxHighlighterService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void app.service.SyntaxHighlighterService.setSyntaxHighlighter(app.pygments.SyntaxHighlighter); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'syntaxHighlighter' defined in class path resource [app/config/SyntaxHighlighterConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [app.pygments.SyntaxHighlighter]: Factory method 'getSyntaxHighlighter' threw exception; nested exception is Traceback (most recent call last):
File "__pyclasspath__/PygmentsSyntaxHighlighter.py", line 2, in <module>
File "__pyclasspath__/pygments/__init__.py", line 37, in <module>
File "__pyclasspath__/pygments/util.py", line 12, in <module>
ImportError: No module named re
...
I am using Spring Boot version 1.3.0.RELEASE via the spring-boot-starter-parent BOM in my Maven POM. In addition, I am excluding the default Tomcat server in favor of Jetty.
My only guess here is that there is some classloader confusion going on due to how Spring Boot embeds jar dependencies into a /lib folder in the resulting packaged executable jar but so far have been unsuccessful working around the error.
Can anyone make a suggestion on how to better diagnose the error or even a direct fix?
Spring boot already has a mechanism for this: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-extract-specific-libraries-when-an-executable-jar-runs
84.6 Extract specific libraries when an executable jar runs Most nested libraries in an executable jar do not need to be unpacked in order to run, however, certain libraries can have problems. For example, JRuby includes its own nested jar support which assumes that the jruby-complete.jar is always directly available as a file in its own right.
To deal with any problematic libraries, you can flag that specific nested jars should be automatically unpacked to the ‘temp folder’ when the executable jar first runs.
For example, to indicate that JRuby should be flagged for unpack using the Maven Plugin you would add the following configuration:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <requiresUnpack> <dependency> <groupId>org.jruby</groupId> <artifactId>jruby-complete</artifactId> </dependency> </requiresUnpack> </configuration> </plugin> </plugins> </build>And to do that same with Gradle:
springBoot { requiresUnpack = ['org.jruby:jruby-complete'] }
In the case of jython you will use org.python:jython-standalone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With