3

Within my deployment procedure I need to deploy specific jar to TOMCAT/lib folder instead of default deploy location WEB-INF/lib. Is there a way to specify this to Maven pom.xml so that I don't need to think of this jar alone?

Specific project is extension for Alfresco which is built based on Alfresco's Alfresco Maven plugin. However this looks to me as requirement that any Java developer should want regardless of used technology. Am I missing the obvious?

Miki
  • 2,493
  • 2
  • 27
  • 39
  • 1
    I think there is no way, because maven is a build tool, not a deploy tool – Jens Aug 17 '16 at 07:38
  • @Jens, wrong. You can deploy with maven. Use command mvn:tomcat deploy. Check the example here https://www.mkyong.com/maven/how-to-deploy-maven-based-war-file-to-tomcat/ – aviad Aug 17 '16 at 07:41
  • @aviad yes there are plugins for deployment, but the Primary use of maven is to build an application – Jens Aug 17 '16 at 07:42
  • 1
    @Jens true. However, there is a big difference between "no way" and "Primary use". Your 1st comment was missleading. – aviad Aug 17 '16 at 07:45
  • 2
    @aviad No it is not. The plugin uses the upload Feature from tomcat and this can only put files in the webapp Directory as i know – Jens Aug 17 '16 at 07:46
  • @Jens so? You still claim that there is "no way" to deploy webapp using maven script? – aviad Aug 17 '16 at 07:48
  • 1
    @aviad No i say not that there is no way to deploy a webapp. I say there is no way to deploy files in the tomcat/lib Folder! – Jens Aug 17 '16 at 07:49
  • @Jens, correct. maven file copy plugin is your friend then, combined with maven deploy(or even without it depending on tomcat and webapp configuration of hotdeploy) will do the magic. How hard could it be? ))) – aviad Aug 17 '16 at 07:53
  • 1
    @aviad Quite hard, especially if you want to deploy to a production server managed by not completely dumb admin. Tomcat's own `lib` folder is something I wouldn't allow a mere developer to mess with. – Jozef Chocholacek Aug 17 '16 at 08:42
  • @Jozef Chocholacek, agree. Prod is a diferrent story. For development environment it would not be a problem. Again, the discussion here was not about "is it good or bad to deploy and drop a jar in tomcat lib dir" but rather "is it possible or not". My point is that it is possible. – aviad Aug 17 '16 at 09:04
  • @Miki I would use a maven-resources-plugin to copy the jar to tomcat lib dir. probably would do it in separate module. There are plenty of examples of how to set pom.xml for that. Check this one http://stackoverflow.com/a/1254372/579580. Then of course you need to tune Tomcat configuration (hotdeploy properties and clearcache properties). Last you need to tune the web.xml of your app. These are just few points and I do not have time now to put and test the working solution for you but I remember that it was definitely achievable with Tomcat6/7 and Maven3. – aviad Aug 17 '16 at 11:03
  • Why would you want that? Are you overriding some ootb classes and you want to make sure your extension takes precedence over ootb artifacts?? – Younes Regaieg Aug 18 '16 at 07:39
  • If so, then there is an easier, and cleaner way of doing so! – Younes Regaieg Aug 18 '16 at 07:40
  • There is no reason I can think of that an Alfresco extension built with the Alfresco Maven SDK would ever need one of its JARs to be copied to $TOMCAT_HOME/lib. – Jeff Potts Aug 19 '16 at 13:43
  • @JeffPotts Actually within webscript I am trying to use DB connection to the 3rd party DB. – Miki Aug 22 '16 at 07:14

1 Answers1

2

I think I understand what you're asking about, let me know if I'm misunderstanding.

Alfresco's Maven Plugin for the SDK Version 3.0.1 (That's what I'm currently using, at least) has a configuration tag called tomcatDependencies which is mentioned in their documentation here.

That being said, it doesn't really explain how to use it.

Here's a snippet that would show configuring a dependency for the Tomcat plugin it uses.

            <groupId>org.alfresco.maven.plugin</groupId>
            <artifactId>alfresco-maven-plugin</artifactId>
            <version>${alfresco.sdk.version}</version>
            <configuration>
                <tomcatDependencies>
                    <tomcatDependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc7</artifactId>
                        <version>12.1.0</version>
                    </tomcatDependency>
                </tomcatDependencies>
                <!-- disabling the flat file H2 database to run the Repo -->
                <enableH2>false</enableH2>
                <!-- using the enterprise DB global properties where we configure oracle DB -->
                <enableEnterpriseDb>true</enableEnterpriseDb>

You can install the jar in your local maven repo and then reference it as a tomcat dependency there.

Here's a link to some directions on how to install that jar to your local maven repo.

Hope this is what you were looking for.

sdumont
  • 99
  • 5
  • I don't think this helps for the use case I asked for but I'll check it out in more details when I find more time and comment your answer. However, thank you for your effort! – Miki Oct 12 '18 at 07:23