How to add a module to 'runtime' class path but not to module dependecies

Hi.

In our project e have a special JAR. At compile time, any other module must not reference code from this JAR. But at run time we create instance - using reflection - a special class which is used as a factory to all other implementation in this JAR.

But: when running from IntlliJ the later does not add this JAR to classpath,becuase - i guess - it see that the executed 'main' method does not depend in any way on this JAR.

How can i solve it.

Thanks
Boaz

7 comments

Module you are trying to run make depended on another module which
contains only that special JAR. If you don't export JAR, you won't be
able to use any classes from it in IDE, but still it will be added to
classpath.

Right click on main module->Dependencies->Add->Module Dependency.

-serg

Hi.

In our project e have a special JAR. At compile time, any other module must not reference code from this JAR. But at run time we create instance - using reflection - a special class which is used as a factory to all other implementation in this JAR.

But: when running from IntlliJ the later does not add this JAR to classpath,becuase - i guess - it see that the executed 'main' method does not depend in any way on this JAR.

How can i solve it.

Thanks
Boaz

0

Hi.

I guess i was missunderstood.

Let say i have 3 modules.

In module A:
+ public interface I {
void sayHello();
}+
In module B:
public class Imp implements I {}

In module M:

+ public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {

Class<?> clazz = Class.forName("Imp");
Class<? extends I> iClass = clazz.asSubclass(I.class);
I i = iClass.newInstance();

i.sayHello();
}+
Module B is depended on A.
Module M is depended on A
At compile time no one is depended on B, And this is requirement, so now, how do i add B to classpath at run time ?

Thanks
Regards
Boaz

0

Hello Boaz,

BN> I guess i was missunderstood.
BN>
BN> Let say i have 3 modules.
BN>
BN> In module A:
BN> + public interface I {
BN> void sayHello();
BN> }+
BN> In module B:
BN> public class Imp implements I {}
BN>
BN> In module M:
BN>
BN> + public static void main(String[] args) throws
BN> ClassNotFoundException, IllegalAccessException,
BN> InstantiationException {
BN>
BN> Class<?> clazz = Class.forName("Imp");
BN> Class<? extends I> iClass = clazz.asSubclass(I.class);
BN> I i = iClass.newInstance();
BN> i.sayHello();
BN> }+
BN> Module B is depended on A.
BN> Module M is depended on A
BN> *At compile time no one is depended on B, And this is
BN> requirement*, so now, how do i add B to classpath at run time ?

You can create a fake module F which contains no sources and depends on modules
A, B and M, and specify it in the "Use classpath and JDK of module" option
in your run configuration.

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


0

Thanks

Do you think this issue worth opening a request ? You see, i have problems explaining to other 40 programmers this fake module.

Thanks,
Regards,
Boaz

0

This one seems similar. Votes anyone?

http://jetbrains.net/jira/browse/IDEABKL-99

Boaz Nahum wrote:

Thanks

Do you think this issue worth opening a request ? You see, i have problems explaining to other 40 programmers this fake module.

Thanks,
Regards,
Boaz

0

See also http://jetbrains.net/jira/browse/IDEADEV-2853 , which seems a better fit. I thought that one was on the Demetra roadmap, but seems to have been dropped off. Sad.

--Dave Griffith

0

Thanks.

This is much better description of the problem from what i tried to say.
I really hope Jetbrains will think about i again.

Thanks
Boaz

0

Please sign in to leave a comment.