0

I have a Maven project, imported from Eclipse, where the dependencies are set to scope provided. When the project is deployed, the jars are deployed as well so that works fine.

While developing, however, I use a "debugging project" that calls the Maven project, and when it runs I get a bunch of Class Not Found errors when the Maven dependencies are set to provided.

If I change the scope of the Maven dependencies to Compile then the project works fine.

If I change the scope of the dependencies to compile, would that change the output of the project? i.e. add a bunch of jars? That would be undesirable.

I also tried to change the Debug Configuration settings and specified the Maven project in "Use classpath of module", but then the files of the debugging project are not found.

How can I specify the classpath to be of both the Maven project and the debugging project, so that classes from both projects including the dependencies will be on the classpath?

Thanks!

isapir
  • 21,295
  • 13
  • 115
  • 116

2 Answers2

0

There are 3 types of dependency scope: compile, test, and provided,

  1. compile: the dependency library will be used in all steps: compile , test and run,
  2. test: the dependency library will only be used in the test
  3. provided: the dependency library will only be used in compile and test, but in the run time, the dependency library must be provided by the container otherwise it will throw class no find issues.

Your issues is that you did not provide the dependency library in the run environment ( container) when running your project.

hope this can help you

Eric
  • 193
  • 2
  • 8
  • Can you be more specific about "you did not provide the dependency library in the run environment"? – isapir Aug 30 '16 at 01:41
  • for example, when we develop a web, the dependency in Servlet jar, we can set it to provided because the container ( such as Jboss ) will be provided the servlet. – Eric Aug 30 '16 at 01:47
  • I understand the different scopes, but I'm trying to find a solution that will work in IntelliJ IDEA given the constraints in the question above. – isapir Aug 30 '16 at 01:48
  • http://stackoverflow.com/questions/3410548/maven-add-a-folder-or-jar-file-into-currrent-classpath, I think that you may get some ideas from this linker – Eric Aug 30 '16 at 02:12
0

How did you import the project to Idea? If the project is opened as a Maven projects, it should work out of box. Can you try to open the project by selecting pom.xml?

summer
  • 1
  • 1
  • The Maven project is being built fine. The debugging project is not a Maven project. It was imported from the Eclipse project model. – isapir Aug 30 '16 at 03:42
  • Idea supports maven very well, so what you need is: get rid of the Idea project settings *.iml and .idea/, and then open the project by selecting pom.xml, DO NOT import from the Eclipse project model. – summer Aug 30 '16 at 05:43