1

I'm fairly new to Java (and stackoverflow for that matter) so I'll try my best to be on-point. I'm using Eclipse Juno and JavaSE 1.7.

I would like to create a data structure which allows me to dynamically sort and retrieve the files I'll need at runtime. These files will be scripts which are processed depending on "where" they were found, or what "type" they belong to. For example, a script relevant to processing commands from the command line would be a "command" script.

I've learned that "directories" in a Jar are more-or-less meaningless, so a clever usage of those proved useless. Although, there are some hacks to make it work, I'd like a more robust solution.

(I have seen the following threads questions and answers: How do I list the files inside a JAR file? and Listing the files in a directory of the current JAR file)

After some thought, I've decided I need to rethink how I'll retrieve these files and this is where I'm at a loss considering my underwhelming knowledge of Java still. I find myself hopping around the internet aimlessly looking for answers, which is when I decided I should ask the question directly.

My questions is this: What is the best approach to creating a meaningful file structure which allows me to retrieve (script) files relevant to how I want to process them at runtime?

Community
  • 1
  • 1
Cory James
  • 144
  • 5

1 Answers1

1

There are many answers to this problem. The real question is how is this information going to be used by the target audience of this program? That is, are you aiming at developers who can whip up some code? Advanced users that just need to add some configuration? Or the general populace with no significant computer experience?

For the first, you could create your own annotations, and find all the classes in the class path that have the annotation. This would allow developers to add classes to your system just by adding some jars to the class path.

For the second, maybe you could have a plugin directory, and iterate over the files there to find the defined extensions? Or maybe have a configuration file that lists the plugins you should use?

Finally, for a general user, you should make it simple. Have the GUI allow the user to specify additional capabilities by location? or website? Like Firefox addins, maybe?

Zagrev
  • 2,000
  • 11
  • 8
  • Sorry for the unnecessarily vague question, I'm just at a severe loss. Yes, it is aimed at other developers who can (hopefully!) code. I'm going to look into your suggestion, thanks! – Cory James Oct 29 '12 at 05:25