Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Reading files from within a Jar (the code is in the jar, not the files)

  • 12-11-2014 2:58pm
    #1
    Registered Users, Registered Users 2 Posts: 7,262 ✭✭✭


    Hi Guys,

    I know that is a fairly confusing title!

    I have a created a Java library that I export as a JAR file to be consumed by other projects.

    The Jar file needs to reads files from project that is consuming the jar

    So I thought I had a solution for this, by using the the classpath.

    The project consuming would add the files required to the root of a resources folder.

    This works fine for desktop projects (there is a sample one here), but I tried to use this functionality of the jar on an android project last night for the first time and it does not find the files that I have put in the resources folder.

    Does anyone have any suggestions to how to make the that I linked to up the top work regardless if its running on Android or desktop? I was pretty tired when I was looking at it last night so I haven't tried too much but just wondering did anyone come across something similar

    What I am trying to achieve is that it will be as easy as possible for consumers of the JAR to make it so the files can be read.


Comments

  • Registered Users, Registered Users 2 Posts: 44 themink


    Did you verify the files in question are actually in the jar file? resources directory is where they are in your source tree but when you compile your project to create a jar, you need to ensure the files are actually included in that jar file. Would depend on how you create your jar really.. are you using maven?

    Also, it would seem like a good idea for your Java library project to get the file location as an input in some form from the code that is using the library. Maybe add a constructor argument for the directory to the library class. Or alternatively have the library read a system property (that would get set by the application using the library).


  • Registered Users, Registered Users 2 Posts: 7,262 ✭✭✭witnessmenow


    themink wrote: »
    Did you verify the files in question are actually in the jar file? resources directory is where they are in your source tree but when you compile your project to create a jar, you need to ensure the files are actually included in that jar file. Would depend on how you create your jar really.. are you using maven?

    Also, it would seem like a good idea for your Java library project to get the file location as an input in some form from the code that is using the library. Maybe add a constructor argument for the directory to the library class. Or alternatively have the library read a system property (that would get set by the application using the library).

    The files are definitely in the APK, as other files in the same folder are used by libgdx.

    Yeah I currently pass in the name of the file on the classpath, but it may have to do more.


Advertisement