0

I have a custom classloader jar <scope>provided</scope> that must be in tomcat/lib before my webapp is run or else it fails to start. I'm using WTP. Is there some way that I can configure M2E/WTP to automatically copy this custom jar to tomcat/lib during the deploy process?

Edit:

It doesn't have to be using WTP, I could also use, for example, a solution using tomcat6-maven-plugin.

Ring
  • 2,249
  • 5
  • 27
  • 40
  • With `provided` scope you're marking it as provided by the server container. If it fails to start it probably would be because it's no available into the server. Have you tried omiting the scope? – Aritz Jul 03 '13 at 20:31
  • If I use the default scope it copies the dependency to WEB-INF/lib and isn't available as a classloader. This jar needs to be in tomcat/lib. – Ring Jul 03 '13 at 22:48
  • Why don't you just copy the jar to that directory? I doubt that you can achieve something like that with Maven or WTP. – Aritz Jul 04 '13 at 05:39

2 Answers2

1

For running an embedded Tomcat instance with the Tomcat Maven plugin, add the JARs required in the Tomcat lib dir as dependencies of the Tomcat plugin itself as shown in this example with the derby and javamail dependencies.

prunge
  • 22,460
  • 3
  • 73
  • 80
  • That works, but now its breaking because the classloader jar depends on another jar in WEB-INF/lib and it can't find it. – Ring Jul 04 '13 at 02:22
  • @Ring Classes loaded from JARs in Tomcat's `lib` directory will not be able to see your webapp classes - see [Tomcat's classloader page](https://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html) for an explanation. Tomcat's `lib` directory is using the `common` classloader, your webapp is a child of `common`, child classloaders can only see parent's classes, parents cannot see children's classes. Might I ask what you are trying to load from Tomcat's common classloader that needs to see your webapp's classes? Perhaps there is another solution? – prunge Jul 04 '13 at 02:36
0

I spent a lot of time researching this problem and here's what I've found:

The tomcat6-maven-plugin does not properly emulate the tomcat boot order, as seen in this jira issue as well as their tomcat6-maven-plugin source.

However, after more research I discovered another maven plugin that I didn't know existed: cargo. Thanks to their excellent documentation I was able to get my project running with the custom (and picky) class loader jar.

Community
  • 1
  • 1
Ring
  • 2,249
  • 5
  • 27
  • 40