Question about multi-module project structure

I have an IDEA 9.0.1 project that has several interdependent modules and I am having problems setting up the dependencies so that IDEA does not get confused.

The modules are a 'Client' module and a 'Server' module.  The Server module is a JEE application that runs as an EAR in JBoss.  It has several JARs that are used by both the Client and the Server.  The Client is a standalone application that connects to the server.

In the past I used two separate projects - one for the Client and one for the Server.  But this caused serious performance problems when I edited a file in one of the projects that was used in the other project - 100% CPU thrashing for long periods.  To avoid this I had to resort to closing the client project whenever I needed to make a change in the Server project.  To avoid this I am trying to configure both modules in a single proejct.

There are ANT build files to compile and package the JAR and EAR files - they are not compiled or built in IDEA itself.

The Client must use the JAR files from the Server module to operate properly - it cannot simply use the classes directly.  To run and debug the Client I need these JARs to be part of the Client classpath, which means they must be declared as dependencies of the Client module.  In these module dependencies, I specify the path to the source files for the classes.

I must also specify the path to the Server source files in order for these files to be 'in the project' so I can use refactoring, etc.  But IDEA gets totally confused because the same class is in the Server source path as well as in the JAR that is used by the Client module.  IDEA is unable to locate classes in the same package as other classes and they show up in red.

How should this project be configured so that IDEA does not get confused between instances of classes in dependent jars and those that are implied by by source files?  I do not want to have to build everything twice: my ANT build files are the primary way the code is compiled and packaged so I don't want to be forced to also build everything in IDEA as well.

Any hints or suggestions will be greatly appreciated.

8 comments

Hello David,

I would set up two regular modules for the client and the server, with one
depending directly on another (not via JARs), and then create a separate
module used only to run the client, which would depend on the server JARs
and the client module and would not include any source or content roots of
its own.

I have a project that has several interdependent modules and I am
having problems setting up the dependencies so that IDEA does not get
confused.

The modules are a 'Client' module and a 'Server' module.  The Server
module is a JEE application that runs as an EAR in JBoss.  It has
server JARs that are used by both the Client and the Server.  The
Client is a standalone application that connects to the server.

In the past I used two separate projects - one for the Client and one
for the Server.  But this caused serious performance problems when I
edited a file in one of the projects that was used in the other
project - 100% CPU thrashing for long periods.  To avoid this I had to
resort to closing the client project whenever I needed to make a
change in the Server project.  To avoid this I am trying to configure
both modules in a single proejct.

There are ANT build files to compile and package the JAR and EAR files
- they are not compiled or built in IDEA itself.

The Client must use the JAR files from the Server module to operate
properly - it cannot simply use the classes directly.  To run and
debug the Client I need these JARs to be part of the Client classpath,
which means they must be declared as dependencies of the Client
module.  In these module dependencies, I specify the path to the
source files for the classes.

I must also specify the path to the Server source files in order for
these files to be 'in the project' so I can use refactoring, etc.  But
IDEA gets totally confused because the same class is in the Server
source path as well as in the JAR that is used by the Client module.
IDEA is unable to locate classes in the same package as other classes
and they show up in red.

How should this project be configured so that IDEA does not get
confused between instances of classes in dependent jars and those that
are implied by by source files?  I do not want to have to build
everything twice: my ANT build files are the primary way the code is
compiled and packaged so I don't want to be forced to also build
everything in IDEA as well.

Any hints or suggestions will be greatly appreciated.

---
Original message URL:
http://www.jetbrains.net/devnet/message/5259022#5259022

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

This is still a problem.

Background: I have been using IDEA since version 4.5 for these modules, but I had always used separate projects for the client and server.  This has become unworkable for whatever reason so I am trying to bundle them into the same project.  There ~300 classes in the client module and ~2K class in the server module.

I did as you said: set up the client and server modules with source roots and a module dependency where the client depends on the server.  I created a runtime only module that depended only on jar files.  The set of jars that are used by the client is a subset of those that are used by the server, i.e. not all the classes in the server module are in the jars that are used by the client (which is hardly a surprise).

There are three modules: Server, Client and Run.  The Server module has a source root 'src', the Client module depends on the Server Module, and the Run module depends on a module library called 'Jar' that consists of server.jar and source path 'src'.

As an example, consider:

src\a\One.java:

=========

package a;

public class One { ... }

src\a\Two.java

======

package a;

public class Two extends One { ...}

Both classes One and Two are in server.jar

Idea can find One and Two via Ctrl-N and they both show up as part of the Server module.

But when you open class Two in the editor, it shows class One in red and offers to import it, even though it is in the same package.  When you accept the import action, the import line shows up in gray as unused.  When you press the 'scroll from source' button in the project tree, it show class Two coming from server.jar, not from the Server module.

It is as if the priority of locating classes is different between different parts of IDEA.  Ctrl-N sees that they are in the Server project, but when they are opened in the editor, the code that parses and analyzes imports thinks the class came from the jar.

So, is there some other mechanism I don't understand that can control where IDEA finds these classes and how it performs its dependency analysis?

0

First, try removing the "third" module and have only the server and client modules. That's how I work with my apps having a Core module + Client module and it works "out of the box".

When everything is working add the third module: it does NOT depend on server, depends on the client and includes in a module lib the server jars. Ensure the client module depends on the server but that it does not export the server dependency.

I see no reason why this shouldn't work, so if something breaks you should post a small demo project that can be tested by someone from Jetbrains.

0

I tried the steps suggested but the problem remains.

Attached is a small sample project and modules that illustrates the problem.

One difference from my actual project is that this demo project uses an artifact to create the jar, where in my case the jars are created by an external ant script and did not have artifacts for the jars.

If anything I would have thought maybe using an aritifact might address the issue, but in each case the problem remains.



Attachment(s):
Multi.rar.zip
0

This is making me crazy.  Today when I opened the demo project (which illustrated the errors yesterday when I created it) there was no problem.

There must be some sequence of events or order of processing that triggers this problem, but it is not obvious.

I have also discovered that the problem goes away if I add the jars that the 'run  client' module requires as dependencies of the 'server' module as well (not the 'client' module).  This is counter-intuitive, since these jars contain the classes generated from the server module and since the source root of the server module and the source path of the jars is the same.  At least that may 'close the loop' and prevent IDEA from getting confused about where the classes really are.

0

Set up 3 modules: client, server, and common. Have both client and server depend on common. Client shouldn't depend on server nor server on client.

0

Tested the Multi project here and gives the same error: it opens ok, but as soon as I edit one of the classes the Two class shows an error.

Seems like a bug: you should create a new youtrack bug entry with the Multi project pointing to this thread.

Try working without the third (Run) module. Maybe create another project using a Client2 module [using the jars] for when you want to debug Client + jars...

Carlos

0

Created YouTrack issue IDEA-53200

0

Please sign in to leave a comment.