Code working from source (IntelliJ), but not with .jar

Kia ora,

I have one major problem and several questions regarding building a .jar file for a project including ORS.

I have the current project structure:

projectname // module1
   libraries
      ...
   graphs // ORS graphs folder
   src
      ors-config.json // I hacked my main class to externalise this file 
      personalpackage
      openrouteservice
         openrouteservice // module2
            ...
         resources
            locales
               // all .resources files
            services
               ...

This structure was the only means by which I could get IntelliJ to recognise ORS.

When exporting a .jar, I set the outermost projectname package as one module, and the internal openrouteservice package as a second. All associated .jar library files (including the ORS Maven files) are packaged alongside the source.

My issue lies in opening the ors_*.resources files. The LocalizationManager class appropriately identifies the location of the files (in IntelliJ and when running the .jar), i.e. it correctly constructs a Resource object for each ors_*.resources file. However, when attempting to convert the Resource object’s URL to a File object via the res.getFile() method call, I get the following exception (.jar only - everything runs correctly when running from source):

class path resource [openrouteservice/resources/locales/ors_pt-PT.resources] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/mak/Desktop/test/package/test.jar!/openrouteservice/resources/locales/ors_pt-PT.resources

When exploring the contents of the .jar, the openrouteservice/resources/locales/ors_pt-PT.resources path certainly exists.

Am I missing something obvious, here? Have I structured the .jar formation incorrectly?

Your help on this is much appreciated. I’m hoping it will be one of my final questions for this forum…!

Ngā mihi,
Mak

I have had to change the LocalizationManager code to make this work. Namely, when res.isFile() == false (i.e. when parsing a .jar), the ConfigFactory in the loadLocalization method needs to call parseURL, not parseFile.

I believe this is working. Nonetheless, your comments appreciated.

If you want to collaborate on this please do so in the repository.

Best regards

Kia ora amandus,

Good to know, thank you. I do not have the capacity to contribute, sorry. I will share my hacked fixes below my posts, here.

Ngā mihi,
Mak