1

I have a Eclipse project where Maven manages the dependencies. I have also few jar files that are not Maven enable and I locate them at src/main/webapp/WEB-INF/lib. I have no issue to build/run the project in Eclipse. I have no issue also to run "mvn:package" after I built the project in Eclipse. However, after I invoke "mvn:clean", if I run "mvn:package", I will get compilation error as it can't find dependency jar files under src/main/webapp/WEB-INF/lib. What I need to do is to rebuild the Eclipse project then "mvn:package". Therefore, I can't invoke "mvn:package" outside Eclipse IDE.

How to resolve this?

Thanks.

Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87

2 Answers2

2

You have to put the not "Maven enabled artifacts" to an appropriate Maven Repository (Nexus, Artifactory what ever) and than change your project to use the dependencies appropriately. Furthermore either you do Maven or not but nothing in between. Maven is a build tool and not only for dependency management. After those changes working with Eclipse will work fine (if you use M2Eclipse). If you correctly use Maven you can do both things via Eclipse or call mvn package on command line.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Our organization has no local Maven repo at this momont. I'm using m2eclipse and it allows me to choose "Enable Dependency Management". – Lee Chee Kiam Aug 08 '11 at 09:45
  • Despite this it make your problem more complex than solve it. So you should make the decision: Either to use Maven or not. Furthermore if you have enabled it your "not Maven like" artifacts will not correctly resolved. so just put them into a Repository manager as i suggested before. – khmarbaise Aug 08 '11 at 09:48
  • If your projects are built using Maven you should push for a company wide repository manager installation, such as Nexus, Artifactory or Archiva. It is very convenient for single developers and indispensable for teams. – Nicola Musatti Aug 08 '11 at 09:50
  • Absolute a must to have company wide repository manager installed as mentioned before. – khmarbaise Aug 08 '11 at 09:53
0

If you can not set up a recommended environment (maven repository) you can add the dependencies as System dependencies to your pom.xml.

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>foo</groupId>
      <artifactId>bar</artifactId>
      <version>1.2.3</version>
      <scope>system</scope>
      <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/foobar.jar</systemPath>
    </dependency>
  </dependencies>
  ...
</project>
FrVaBe
  • 47,963
  • 16
  • 124
  • 157
  • system scope dependencies are intended for artifacts which are outside of the project so in particular not designed for artifacts which are part of the project. You will get warnings during a build with Maven 3.0.X. The best solution is to put them into a Repository Managed repository. – khmarbaise Aug 08 '11 at 10:45
  • @khmarbaise I really know that this is not best practise. But if a solution without a managed repository is needed and when you want to share your project (so you can not only install the dependencies inside your local repository) with others - what should you do instead? (Don't get my wrong - I like and recommend the use of a managed repository for build artefacts but is it soooo bad to place a dependency inside the project as it will be also part of the running system later too?) – FrVaBe Aug 08 '11 at 11:22
  • @K. Claszen, I have a number of external jars (> 10), do I have a way to include all jars under a folder instead of adding the dependencies 1 by 1? Thx. – Lee Chee Kiam Aug 08 '11 at 11:47
  • @CK Lee As I know there is no other way than to add them one by one (the number of your external jars seems to be an evidence that you really should consider to place them to a managed repository :-)). – FrVaBe Aug 08 '11 at 12:06
  • I managed to find some jar files from other repo. Now the number of non-maven enabled jars left 2. I adopt your solution. Anyway, I will push my CM team to follow khmarbaise's answer in future. – Lee Chee Kiam Aug 09 '11 at 01:04