Adding extra paths to classpath on Run only

Any way to add extra libraries to the classpath when Running an app? I don't want to add them as dependencies because there is a huge number of libraries and they aren't needed until runtime. If I use -cp, then it loses Ideas classpath that is based on the dependencies.

10 comments
Comment actions Permalink

Hello Travis,

Unfortunately there is no way to do it right now. But we plan to implement
runtime classpath configurable from run configurations.

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

Any way to add extra libraries to the classpath when Running an app? I
don't want to add them as dependencies because there is a huge number
of libraries and they aren't needed until runtime. If I use -cp, then
it loses Ideas classpath that is based on the dependencies.



0
Comment actions Permalink

Thanks Anna. Is this planned for 7.0?

0
Comment actions Permalink

As workaround, couldn't you just create a dummy module, e.g. if you have a module named "App", then create another module "AppRuntime" depends on "App" and contains additional module libraries.

Then, in the run configuration, set the "Use classpath and JDK of module" setting to "AppRuntime".

I haven't tried such a thing myself, but it might work?

0
Comment actions Permalink

Ya, but then you still make Idea cache all those jars so it's bound to be a waste of resources. By including them at runtime Idea doesn't even have to know anything about them.

0
Comment actions Permalink

On this one, I'll express some well-earned agnosticism. Per my memory, it was originally asked for in the 2.0 time frame, managed to get on the roadmaps for both 4.0 and 6.0 (but not 4.5 or 5.0), and still hasn't seen the light of day. My preference isn't for specifying classpath in the run profiles (for which there may be dozens on a large project), but rather flagging libraries as "runtime-only", so that they aren't completed/cached/navigated-to/etc. I'd take either. The canonical use-case is JDBC drivers, which are needed at runtime but should never be depended on.

--Dave Griffith

0
Comment actions Permalink

It's doable, but very hacky. You also still risk IDEA attempting to complete a class that you only want available at runtime, which is tedious. More importantly, IDEA project/module structures should contain all of the important information about the edit-time, build-time, and run-time structures of the project. That some libraries are only needed at runtime is a common and important constraint that IDEA just doesn't get.

--Dave Griffith

0
Comment actions Permalink

That sounds like a good way to do it so it's in the project settings.

0
Comment actions Permalink

IMO the perfect solution (which by an astonishing coincidence fits perfectly with my shiny new build based on Ivy ;) ) is to have various types of dependencies. Ivy supports this with the notion of configurations. So I can state that a module depends on a library (or other module, Ivy doesn't distinguish) for compile, but not for run. Or for test, but not for compile. It allows some very flexible configurations, and you can often avoid circular dependencies when you need a dependency only for a particular use case. I love the system we now have with Ivy, sadly IDEA is sadly deficient by comparison.

Cheers,
Colin

0
Comment actions Permalink

Hello Colin,

IMO the perfect solution (which by an astonishing coincidence fits
perfectly with my shiny new build based on Ivy ;) ) is to have
various types of dependencies. Ivy supports this with the notion of
configurations. So I can state that a module depends on a library (or
other module, Ivy doesn't distinguish) for compile, but not for run.
Or for test, but not for compile. It allows some very flexible
configurations, and you can often avoid circular dependencies when you
need a dependency only for a particular use case. I love the system we
now have with Ivy, sadly IDEA is sadly deficient by comparison.


Maven 2 has a simiar feature. It would be very nice to have some support
and UI for this in IDEA. IIRC, someting similar was part of the Demetra roadmap,
but not implemented.

-tt


0
Comment actions Permalink

The corresponding long-term issue is available for voting: IDEADEV-2853.
While we all are waiting I wonder: is it possible to create a simple IDEA plugin which takes some special system property and adds its content to Run/Debug Configuration's classpath?

0

Please sign in to leave a comment.