Sharing source code between modules

I have a project where I want to share source code between two java modules.
They are organized like this: I have a main Java module located in "projectroot/" and another module located in "projectroot/utility/".
In the utility module I use some of the classes from the main module, so I created a project library with attached sources in "projectroot/src". This didn't give me access to the main modules in the utility module (still 'cannot resolve...' errors).
By coincidence, I found out I had to add "projectroot/classes" to the project library. OK this meant that my utiliy module classes could 'see' the main module classes. BUT - of course only the classes that are compiled in the classes dir. This means that it didn't register if I change something in the main module classes.
Other strange things also happened - I suddenly had to use the same project library in the main module in order to see the classes, even though they reside in the sources directory under the main module's content root. Strange.
I gave up ... my solution was to remove the utility module and just have one, big module including it.

Is it just me, or could this be done somehow. It seems reasonable that you should be able to use sources from another module in idea, doesn't it?

Regards,

Kim

5 comments
Comment actions Permalink

Maybee you should unfuxor that project layout instead. If it's not a module, don't use an IDEA module. If it's not a library, don't register it as such.

I mean, Utility module uses classes from the main module? Isn't it supposed to be the other way around?

0
Comment actions Permalink

Hi,
Thanks for the quick answer.

The main module is a web application. The "utility" part of it is a separate application - a command line application used for utility tasks on the same database. I need to share the database classes.

The project layout is like it is because of historical reasons, dating back to before Idea even supported modules.
Since I'm not the only one coding on this project, I'll have to have very good reasons in order to convince my colleagues to change the base project layout (and all the other changes that might infer) "Pleasing Idea" is not a good reason in itself...

I was using the library method for sharing code because that seemed the only way to do it - you cannot have two modules with same content root, so it's hard to share source trees through that mechanism.

Kim

0
Comment actions Permalink

Then setup three modules like:
"base" which has everything BUT the web content files (jsp etc)

"web" which only has web content, set it to depend on "base"
"utility" which has its classes only, set it to depend on "base"

Then you can play around with the Exclude-setting in the Path-tree of the Paths applet in IDEA to only show relevant content in Project View.

0
Comment actions Permalink

That is how we have ours.

We have a program that provides "alert" functionality. This is the
library that everyone depends on. Then there is a web interface and a
phone interface. There are 3 modules. 2 java, 1 web.

Norris Shelton
Sun Certified Java Programmer




Patrik Andersson wrote:

>Then setup three modules like:
>"base" which has everything BUT the web content files (jsp etc)
>
>"web" which only has web content, set it to depend on "base"
>"utility" which has its classes only, set it to depend on "base"
>
>Then you can play around with the Exclude-setting in the Path-tree of the Paths applet in IDEA to only show relevant content in Project View.

>

0
Comment actions Permalink

Thanks guys,

I was obviously completely off-track here. While I was looking for source code paths in the Idea GUI, it never occured to me that the functionality I was missing is exactly the Idea notion of 'dependencies'!
The layout is now as before: the 'base' module has content root at the project root directoy with appropriate exceptions for the underlying module directories. The 'utility' module has the content root 'base/utility'.
Just as you propose, and just like I did before.

The only difference is that before I used a library with attached source code to make the 'base' code visible in the utility module.
Now in the Dependency tab, I just made my utility module depend on the base module. Like you said.
And it works like a charm.

That sums the whole thing up to another RTFM (Read the F....../Fine Manual) post to which I blushingly apologize!
THANK YOU ALL!

Kim

0

Please sign in to leave a comment.