Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(LoadError) no such file to load -- asciidoctor-diagram (Use after fat Jar deployment) #1286

Closed
Ghuu420 opened this issue Oct 4, 2024 · 7 comments · Fixed by #1288
Closed

Comments

@Ghuu420
Copy link

Ghuu420 commented Oct 4, 2024

Ive been working on a Spring boot project lately that uses the asciidoctor and keep having this problem so hopefully someone is familiar with it and could say something about it ..

Its a basic projekt to creates different types of reports. Locally using a IDE (ECLIPSE) everything works fine but after the deployment , some problems start to happen. I am using java 17 and Apach Maven 3.9.1 locally .

The project is built into a fat executable Jar which is used for deployment (Linux Ubuntu (Java 17 too)) using these dependencies and build plugins

<dependencies>
   <dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
    </dependency>
     <dependency>
	    <groupId>org.apache.poi</groupId>
	    <artifactId>poi-ooxml</artifactId>
	    <version>3.17</version>
    </dependency>
    <dependency>
	    <groupId>org.asciidoctor</groupId>
	    <artifactId>asciidoctorj</artifactId>
	    <version>3.0.0</version>
	    <scope>compile</scope>
    </dependency>
    <dependency>
	    <groupId>org.asciidoctor</groupId>
	    <artifactId>asciidoctorj-pdf</artifactId>
	    <version>2.3.18</version>
	    <scope>compile</scope>
    </dependency>
    <dependency>
	    <groupId>org.asciidoctor</groupId>
	    <artifactId>asciidoctorj-diagram</artifactId>
	    <version>2.3.1</version>
    </dependency>
</dependencies>

build_screen

I double checked after the successful build, that the asciidoctor-diagramm is unpacked and existant (at xxx1.0.0.jar\BOOT-INF\classes\gems\asciidoctor-diagram-2.3.1).
After the deployment , calling an Api to generate a pdf report , I keep getting this error :

[org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.jruby.exceptions.LoadError: (MissingSpecError) Gem::MissingSpecError] with root cause : org.jruby.exceptions.LoadError: (LoadError) no such file to load -- asciidoctor-diagram
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1184)
at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85)
at RUBY.

(<script>:1)

I see that the .adoc file for the report gets created but I think the issue happens in the conversion of the adoc file into pdf file.
I found some of other similar issues such as #1263 (comment) , which pointed out that it is a sprinboot handling problem which should be treated by unpacking the related dependencies in the build plugin but somehow i couldn't overpass it ..

@abelsromero
Copy link
Member

abelsromero commented Oct 4, 2024

I found some of other similar issues such as #1263 (comment) , which pointed out that it is a sprinboot handling problem which should be treated by unpacking the related dependencies in the build plugin but somehow i couldn't overpass it ..

That's it, but I see you have maven-shade-plugin also, which is not necessary and could be messing with the final JAR. My suggestion is to remove it and use the normal generated SpringBoot Jar + the requiresUnpack config

@abelsromero
Copy link
Member

PS: if this is going to end-up in a Docker image, I strongly suggest using the provided buildpack for it to avoid further classpath issues, see this section in the blog https://spring.io/guides/gs/spring-boot-docker#_build_a_docker_image_with_maven

@Ghuu420
Copy link
Author

Ghuu420 commented Oct 4, 2024

Thank you for the hints. But I tried to adapt it my Build plugin like you said and used this instead :

buildPlugin

I redeployed it as a systemd service and it was running and active , but i get the same error again by calling a pdf generation Api

[transaction.id= trace.id= span.id=] ERROR [https-jsse-nio-7083-exec-2] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]] - Servlet.ser>vice() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.jruby.exceptions.LoadError: (LoadError) no such file to load -- asciidoctor-diagram] with root cause
org.jruby.exceptions.LoadError: (LoadError) no such file to load -- asciidoctor-diagram
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1184)
at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85)
at RUBY.

(<script>:1)

and the .adoc file is still being created ..

@abelsromero
Copy link
Member

abelsromero commented Oct 4, 2024

I was able to reproduce it. The issue is that transitive dependencies need to be added too:

<requiresUnpack>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj</artifactId>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-pdf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-diagram</artifactId>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-diagram-plantuml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-diagram-batik</artifactId>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-diagram-ditaamini</artifactId>
        </dependency>
    </requiresUnpack>
</configuration>

To be honest, not very easy to manage. If I may, I'd suggest 2 alternatives:

  1. If you are using Spring Boot 3.3.+ you can use the extracted JAR (no need for extra requiresUnpack config).
    I tested it and is working fine, but you'll need to run the extract step as part of your installation/deployment. See the docs https://docs.spring.io/spring-boot/reference/packaging/efficient.html. As an extra, this improves startup time.
  2. Use Gradle, the configuration in Gradle allows to use a wildcard that will add all dependencies in a concise way
bootJar {
	requiresUnpack '**/asciidoctorj-*.jar'
}

@Ghuu420
Copy link
Author

Ghuu420 commented Oct 8, 2024

Sorry for the late feedback , i wasn't able to test the solutions on the weekend.
Adding the transitive dependencies to the requiresUnpack Config solved the problem for me 😄
I couldn't try the other options since I'm currently mainly working on SB 3.2.3 and Maven , and I dont have the option to change that atm ..
Thanks for the support! 😃

@abelsromero
Copy link
Member

No problem at all, glad to help.
As a side note, SB 3.2.x goes out of Open Source support next month, you may consider upgrading https://spring.io/projects/spring-boot#support.

@Ghuu420
Copy link
Author

Ghuu420 commented Oct 8, 2024

Thank you for the heads-up ! I’ll definitely look into upgrading soon :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants