tags:

views:

102

answers:

2

I'm currently developing for Android using Eclipse. I have a lexicon viewer application (with package name "com.mycompany.myviewer") that I want to reuse multiple times, just changing specific resources such as app name and icons.
For example, I have a certain publisher "Publisher1", who publishes the lexicons "Lexicon1" and "Lexicon2". I would need to two applications: App1 with certain name and icon, and App2 with another name and icon.
What is the best way of doing this in Java? In visual Studio (and C++) I could create two projects based on the lexikon viewer app and use conditional resources to get the right name and icon. Is there some way of doing something similar in Java?

+1  A: 

You can pack your lexicon viewer classes in its own .jar archive to use as library in the actual projects. Next you can define the resources in a property file like lexicon_viewer.properties that you allocate through a classloader using getResourceAsStream:

Properties props = new Properties();
String propFilename = "lexicon_viewer.properties";

InputStream is = PropertiesUtil.class.getClassLoader().getResourceAsStream(propFilename);

props.load(is);

In your project .jar archives you include the lexicon properties file with the specific resource information like aplication name, icon filename, etc. The icon you can load via the same mechanism. For test purposes you can create a property file in the filesystem making sure it is early in the classpath.

rsp
+1  A: 

In Eclipse you can have multiple projects in the same workspace depend on each other.

  1. Import the core project and the dependant projects into the same workspace.
  2. Right click on a dependant project in the project explorer, select the menu item: Build Path -> Configure Build Path
  3. This will bring up the Java Build Path dialog box, select the Projects tab.
  4. Click on the Add button to the core lexicon viewer application project as a dependency for App1.
  5. Repeat the process for App2 and any other projects you want to depend on your core project.
Tendayi Mawushe