0

I have Java Gradle project and I am using third party library in my project which requires license.

I added license_.cxl on following path.

src/main/resources/license_.cxl

Before using any third party lib function I need to setLicense(String licenseFilePath). When I test the code using IntelliJ IDEA its working fine.

But when I create jar file and try to execute the same function, its giving me error - "Unable to set License, License file not found: src/main/resources/license_.cxl"

Then I added license_.cxl on custom folder(outside project directory) and hardcoded that path in my code then its working fine when I execute code by running jar file.

So I started checking third party code. I saw their code is trying to create new license file using provided path. I tried may stackoverflow solution to provide resources folder license_.cxl file path but nothing works for me other than keeping file on custom directory to run code using jar file.

Looks like issue is third party code is not able to create a new license file from the path where license_.cxl file is packaged inside my jar file.

How I can resolve the issue so that I can test the code by running jar file without keeping license_.cxl to custom directory.

Updated - following is the dir structure when I unzip jar file and license_.cxl file is inside BOOT-INF\classes folder. enter image description here

stackUser
  • 545
  • 3
  • 9
  • 21
  • 1
    Does this answer your question? [How to really read text file from classpath in Java](https://stackoverflow.com/questions/1464291/how-to-really-read-text-file-from-classpath-in-java) – aksappy Aug 17 '21 at 12:25
  • No, nothing worked for me from that link. I need solution so that third party code should be able to create new file when I provide path of the file from resources folder while running jar file. – stackUser Aug 17 '21 at 12:32
  • Remove `src/main/resources/` from `src/main/resources/license_.cxl` and try. – seenukarthi Aug 17 '21 at 12:33
  • @KarthikeyanVaithilingam tried that as well. when I extract/unzip the jar I see file is under BOOT-INF/classes so I dont think it should work. – stackUser Aug 17 '21 at 12:36
  • please refer the updated question for jar file structure when unzipped. – stackUser Aug 17 '21 at 12:42
  • 1
    The variable name `licenseFilePath` indicates that your third party lib is expecting a path to a regular file. This means that you cannot use a file packaged inside your JAR. If there's no other method available then the only way would be to create the file upon startup of your application (using the contents packaged inside your JAR). – slauth Aug 17 '21 at 12:48
  • yes, third party lib is expecting a path to a regular file and by using regular file path its trying to create new file and use the new one. – stackUser Aug 17 '21 at 12:52
  • Your build or deployment will need to ensure the file is deployed in the right location for your application. The `resources` directory is a source-only feature for resources that need to end up in your JAR file. If you want to know alternative deployment strategies so you use it _"without keeping license\_.cxl to custom directory."_, then you should contact the company that licensed this to you. – Mark Rotteveel Aug 19 '21 at 14:10

0 Answers0