Search code examples
gitibm-cloudwebsphere-liberty

WEB-INF missing - Adding JAR files to a Liberty application in Bluemix


I have created an application using the Liberty boilerplate. I have added GIT to create and populate repository for the app. I need to add an additional .jar file to my application. However, when I go to the GIT repository and look at the files structure I don't see the WEB-INF directory.

How can I add .jar files to my project so that the files end up in the WEB-INF/lib directory of my application?

Please advice.


Solution

  • Yes, you are right, the structure of the app repository has changed as it seems that the build has been changed from ant to maven based. If you want to add a jar to the standard java web app structure which expects the jar to be located in the WEB-INF/lib folder you need to define a dependency which will point to the jar. All maven dependencies need to come from a repository so before you can define a dependency for your jar you need to declare a local repository which holds the jar. Here are steps you can follow:

    1. In the root of you project in GIT create new folder and call it 'repo'
    2. In the 'repo' folder create a folder structure which defines the project the jar comes from and version of the jar like: /com/mycomp/myproject/1.0
    3. Import thejar.jar into the 'repo/com/mycomp/myproject/1.0/ folder
    4. Rename thejar.jar to thejar-1.0.jar (or whatever version you have used);
    5. In the pom.xml file add the following:

      <repositories>
       <repository>
        <id>ProjectRepo</id>
        <name>ProjectRepo</name>
        <url>file://${project.basedir}/repo</url>
       </repository>
      </repositories>
      
      <dependencyManagement>
       <dependencies>
        <dependency>
         <groupId>com.mycomp.myproject</groupId>
         <artifactId>thejar</artifactId>
         <version>1.0</version>
        </dependency>
       </dependencies>
       </dependencyManagement>
      
      <dependencies>
       <dependency>
        <groupId>com.mycomp.myproject</groupId>
        <artifactId>thejar</artifactId>
        <scope>compile</scope>
       </dependency>
      </dependencies>
      
    6. Commit and push the changes. Your should see in the war WEB-INF/lib/thejar.jar I hope it helps. Please let me know how does it work for you. Good luck. Kris