0

I am using Maven and Eclipse to create a archetype webapp project. my project is dependent on another project in the workspace (say, projectA), and everything works well at compile time. Now i have to add the entry for projectA in my deployment assembly, so that it is included in the created WAR, otherwise i get a class not found error when the webapp runs, for the classes i have used from projectA.

Now, everytime I right click --> Maven --> Update , the projectA entry from deployment assembly is automatically removed, and i have to manually add it again before creating the war.

P.S: I have seen similar questions about Maven Dependencies getting removed from deployment assembly, but that does not seem to be the case here, only the projectA entry is removed. I have <packaging> war </packaging> in my pom.xml as well.

Using Eclipse Luna.

gaurav5430
  • 9,899
  • 5
  • 32
  • 73
  • How did you create the Maven project from Eclipse? – Tunaki Oct 21 '16 at 11:04
  • create new --> Maven Project --> archetype webapp – gaurav5430 Oct 21 '16 at 11:04
  • Did you install m2e-wtp? – Tunaki Oct 21 '16 at 11:05
  • yes, and i have been creating a lot of maven projects, without any issues, but did not need to have any project dependencies (outside of pom.xml) till now. – gaurav5430 Oct 21 '16 at 11:07
  • Ok, and is there Workspace resolution enabled (right click > Maven > Enable workspace resolution)? Can you also show what your `.classpath` looks like? – Tunaki Oct 21 '16 at 11:09
  • Looks like what you need is a multi module build, or you have to use an artefact repository to put the artefact of project A to it and add a dependency to this artefact – Jens Oct 21 '16 at 11:09
  • yes, Workspace resolution is enabled (by default). Anything specific you want to look for in .classpath ? – gaurav5430 Oct 21 '16 at 11:10
  • @Tunaki the classpath has an entry for projectA, if that is what you are looking for with kind="src" – gaurav5430 Oct 21 '16 at 11:12
  • 1
    That's not good then. That dependency needs to be a Maven dependency, and it should not be listed in `.classpath` (it should be brought in automatically by `org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER` line). Is `projectA` a Maven dependency listed in the POM? – Tunaki Oct 21 '16 at 11:14
  • @Tunaki ohk, inside that i only have an entry for WEB-INF/lib , any idea how this could be corrected? – gaurav5430 Oct 21 '16 at 11:15
  • Not corrected, this is the right thing to have. Just make sure `projectA` is a Maven dependency. – Tunaki Oct 21 '16 at 11:16
  • @Tunaki yeah, that's what I meant, what to do so that projectA appears in the correct place in .classpath ? How to make sure that it is a Maven dependency ? – gaurav5430 Oct 21 '16 at 11:17
  • Just add it to your POM. Inside a `` block, like all the others dependencies. Don't add it manually through Eclipse. – Tunaki Oct 21 '16 at 11:18
  • Ohk, will try that, but when i add it manually to Deployment Assembly and export as jar, it works as expected, so for that, it does not need to be a maven dependency ? – gaurav5430 Oct 21 '16 at 11:22
  • @Tunaki Moreover, projectA is not a Maven project, so I am not sure how to add it using block – gaurav5430 Oct 21 '16 at 11:24
  • It probably "works" because you're doing all the operations inside Eclipse itself with no interaction with the Maven side of things. But as far as Maven is concerned, that `projectA` dependency does not exist, so when m2e is taking over (Eclipse plugin for Maven), it doesn't take into account. If `projectA` isn't a Maven project, you need to install it, look at http://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-in-maven-project – Tunaki Oct 21 '16 at 11:24
  • @Tunaki I tried looking for ways to add a non-maven project as a dependency for a maven project, any pointers? – gaurav5430 Oct 21 '16 at 11:52
  • Yes, look at the link I gave you http://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-in-maven-project. Use `mvn install:install-file` to install the file into your local repo. – Tunaki Oct 21 '16 at 11:53
  • There is a very simple way to "install" projectA jar. Just add the block and after execute mvn install, copy the jar inside the generated folder in your REPO – Marco A. Hernandez Oct 21 '16 at 11:55
  • @Tunaki Thanks a lot for the clarifications, will look more into this. – gaurav5430 Oct 21 '16 at 12:04

1 Answers1

0

as pointed out by @Tunaki in comments:

In a maven project, the dependencies have to be specified in pom.xml. In my case, i was using Eclipse and specified a dependency using Eclipse, so Maven did not recognize it, and i could not use any Maven specific build tools on the project, without the external dependency being removed.

(Although, it was possible to use Eclipse tools for creating WARs which take care of both maven dependencies and others)

gaurav5430
  • 9,899
  • 5
  • 32
  • 73