2

I have a case where I need to unpack the library using the:

spring-boot:repackage:requiresUnpack

Otherwise, the other library from the project is not able to work properly. As stated in the link, the selected libraries are unpacked and copied over to the temporary directory. Unpacking the libraries to the temp directory isn't great idea if I would like to keep the application running longer that the temp files expiration time. The files would be removed and application will just stop working properly.

  • Is there a way to specify the different target directory?
  • Is there a reason why the temp location is good place for the application libraries?

So far, I was able to change the location target location via overwriting the TMP and TEMP environment variables but that sounds like terrible idea in the long run.

Appriciate any help here.

5
  • Did you try with outputDirectory docs.spring.io/autorepo/docs/spring-boot/1.5.10.BUILD-SNAPSHOT/…
    – bittu
    Nov 14, 2018 at 18:33
  • What is it about the library that causes you to unpack it? Given that spring-boot is an implementation by convention, and this steps outside of convention, my personal solution to your problem would be to figure out a solution to not require the unpacking of the library.
    – Kieveli
    Nov 14, 2018 at 20:12
  • outputDirectory is used for location of the target jar file not the place where libraries will be unpacked during the runtime; @Kieveli this functionality is supported by spring-boot docs.spring.io/spring-boot/docs/current/reference/html/… exactly for the case I need to use; unfortunately I'm dealing with proprietary libraries which I cannot change Nov 15, 2018 at 8:00
  • I'm still curious as to the reasons behind needing to unpack it - but if you'd rather not share, that's ok. My spring-boot runs as a Tomcat instance. With tomcat, it often uses the temp space to run the web application. This does not mean that the temp folder will get arbitrarily removed. Have you experienced an issue where the unpacked library has been removed while the web service is running?
    – Kieveli
    Nov 15, 2018 at 13:41
  • I cannot share the details about the library (confidentiality) but it require the unpack to work properly. Yes, I experienced this issue badly on the production environment, when the application suddenly stop working (after 10 days) with the ClassNotFound-like exception. Nov 15, 2018 at 14:53

1 Answer 1

2

This problem is not specific to "requiresUnpack" only, this is how spring-boot/tomcat handles its temporary files. So it might also surprise you in other areas.

There is an issue describing that behavior: https://github.com/spring-projects/spring-boot/issues/5009

Workarounds:

  • use server.tomcat.basedir to define Tomcat base directory. If not specified, a temporary directory is used.
  • use -Djava.io.tmpdir=/var/tmp to start the app with different temporary directory.

Another solution would be to NOT unpack your library. Don't store it in your fat jar, but store it somewhere on the classpath.

3
  • 1
    I will go with -Djava.io.tmpdir=[location], maybe in future there wil be a way to configure this in other way: github.com/spring-projects/spring-boot/issues/15180 Nov 16, 2018 at 10:37
  • @GrzegorzGajos Do you append the temp location in class-path as well? Once the intended jars are unpacked, how does the application find them? I mean, the jars have to be available on the class path, right?
    – ds459
    Aug 19, 2021 at 21:45
  • @ds459 The application/Tomcat is looking for them in default dir. This is out of the box behaviour. I didn't have to append the temp location to the classpath. Sep 15, 2021 at 12:31

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.