How to adjust my project


could you please help me with adjusting my project in IDEA 7.0.3. I have some problems with sources and don't know how to solve them.

I have two modules, for server and for client, in one project, without any special facets (like ejb or web), only plain java sources.
My client is a standalone desktop application. It uses several jars, including two jars with classes from server.
My modules are not dependent in IDEA at the moment. In order to launch client, I just copy two jars, from server folder to client lib folder, and launch client from IDEA, because these jars are in client module's classpath.

The problem is with debugging client, because debugger doesn't see sources for this jars.
I do the following:
1. I attach sources to these jars, pointing to the src folder of the server module. But this entails a lot of problems: when I step into such server class, all imports in source are red, all other server classes are underlined with red. And to resolve imports IDEA suggest adding.. jars from client lib folder! This two jars from server side! If I add them, my server module gets this jars (from client module) to it's classpath! Something terrible. I think this sources are overlapped with the same sources in the server module..

2. However, the above problem can be solved if server sources are copied to some unknown for IDEA dir, and I attach them to these jars in client module. It seems that in this case there are no conflicts with server sources. But it is not an elegant solution. I have to copy sources regularly..

Please, give me advise how to configure my project. I think my situation is so common, that there should be a standard solution. Maybe I should adjust modules dependencies?

Thanks for your attention.

Comment actions Permalink

Hello Alex,

I have not investigated your problems in details, the following is just a
common throught.

If server and client are different products, i.e. they are not built together,
and not distributed in the same delivery, then they probably should be different
IDEA projects, not modules. BTW, you can adjust server project settings to
build jar directly in the client's lib directory, avoiding additional copying.

If they are the same product, built together, then you can set module dependency
from client to server and get rid of superfluous workarounds with jars.


Comment actions Permalink

simply create a new module that will contain the classes which are
common for both the server and the client module.
Then make the server and client modules to depend on it.
Note that different modules may have classes in same packages (so
when you move part of your server code to the new common module you
don't need to refactor it).
You may have several such "library" modules, if needed.

When you build the application and make different jar files for the
client and the server, it simply doesn't matter from which modules come
the classes for specific jar file, as long as all the needed classes can
be loaded by the VM in runtime.

When you launch the server or the client app, IDEA will include the
output directory with the common classes in the classpath automatically
(because of the compile-time dependency).

IMHO, this is the clearest solution.

We have one server and several client applications, each of which is
a module in the same project. We have a module that contains code common
for all other modules (e.g. utility classes). We have also a module with
common code for all the clients (but not for the server). With the
proper dependencies this works just fine. Jar files for the deliveries
we create with an ant script.


Comment actions Permalink

Thank you, Alexander and George!
I will suggest these variants to our lead dev :) I think we will adopt these ideas.

Spasibo za soveti ;)


Please sign in to leave a comment.