09-30-2009 02:23 PM
HI, I have a workspace, which contains 4 different projects.
I package all the project under the same path, like package com.xxx.app.version1;
I have made a new class, say DataStruct , it will be used in multiple projects.
If I only define the DataStruct in one project, how can the other projects reference this class ?
I don't like to put the same class file into each project, since it causes consistency problems.
Solved! Go to Solution.
09-30-2009 02:58 PM
My own solution:
add one new project name xxlib into that workspace.
add all the newly defined classes into this project. pack them like com.xxx.lib;
build the jar file of this xxxlib first. then add this jar file into the other projects that need the new classes.
(for each project, properties->build->add jar)
in those project files that need the new class, add "import com.xxx.lib;"
10-01-2009 01:50 PM
I know you've marked this solved, but I'm not sure you've solved your problem. What do you do if you want to change the common class? Rebuild the jar file? That's okay on a relatively stable project, but not so good for early development when things change fast.
You don't say what IDE you're using, but most IDE's have a way to establish dependencies between projects.
For example, let's say you're using eclipse and you have three projects, ProjectA, ProjectB, and ProjectC. ProjectC has your common class in it. You want to telleclipse that ProjectA and ProjectB are both dependent on ProjectC. Then if you change something in ProjectC (like your common class), ProjectA and ProjectB both get recompiled as needed. It will even handle the imports for you.
You would select ProjectA and go to its Properties (either use the Project menu item or right-click the project and select Properties from the pop-up), then in the Properties dialog select the Projects tab. Click the "Add..." button and you get a list of the other projects, ProjectB and ProjectC. You click the checkbox for ProjectC and then click the "Ok" button. That puts you back in the Properties dialog, and you click the "Ok" button there.
Then do the same thing for ProjectB: ProjectB --> Properties --> Projects, click "Add..." and you see ProjectA and ProjectC, click the ProjectC checkbox, the "Ok" button, and the Properties "Ok".
I guess I ought to go look at the JDE and see how it's done there.
Forgive me if this is stuff you already know; I could not tell from your post.
10-01-2009 02:34 PM
thank you very much.
Actually, i think your solution is better than what I did. I do appreaciate it.
I am working on JDE 4.7.0. I have tried what you suggested, it works.
It is easy to do that in JDE:
(I just reference your name in the example, i.e., ProjectA, B, C)
hightlight Project C -->right click mouse --> choose [properties] --> choose [application] tab --> set the project type to [library]
hightlight ProjectA --> right click mouse --> choose [project dependencies] --> check project C
do the same for the rest of the projects. ...
I am changing my projects to your way, which is better.
As you said, my solution works fine for a stable jar, but if I need to update my jar file frequently, yours is better.
Thanks a lot.