Maven: How to include jars, which are not available in reps into a J2EE project?

后端 未结 10 969
失恋的感觉
失恋的感觉 2020-11-28 18:17

in my J2EE project I\'ve a couple of dependencies, which are not available in any Maven repository, because they\'re proprietary libraries. These libraries need to be availa

相关标签:
10条回答
  • 2020-11-28 18:36

    For people wanting a quick solution to this problem:

    <dependency>
      <groupId>LIB_NAME</groupId>
      <artifactId>LIB_NAME</artifactId>
      <version>1.0.0</version>
      <scope>system</scope>
      <systemPath>${basedir}/WebContent/WEB-INF/lib/YOUR_LIB.jar</systemPath>
    </dependency>
    

    just give your library a unique groupID and artifact name and point to where it is in the file system. You are good to go.

    Of course this is a dirty quick fix that will ONLY work on your machine and if you don't change the path to the libs. But some times, that's all you want, to run and do a few tests.

    EDIT: just re-red the question and realised the user was already using my solution as a temporary fix. I'll leave my answer as a quick help for others that come to this question. If anyone disagrees with this please leave me a comment. :)

    0 讨论(0)
  • 2020-11-28 18:38

    Install alone didn't work for me.

    mvn deploy:deploy-file -Durl=file:///home/me/project/lib/ \
      -Dfile=target/jzmq-2.1.3-SNAPSHOT.jar -DgroupId=org.zeromq \  
      -DartifactId=zeromq -Dpackaging=jar -Dversion=2.1.3
    
    0 讨论(0)
  • 2020-11-28 18:43

    You need to set up a local repository that will host such libraries. There are a number of projects that do exactly that. For example Artifactory.

    0 讨论(0)
  • 2020-11-28 18:44

    If I am understanding well, if what you want to do is to export dependencies during the compilation phase so there will be no need to retrieve manually each needed libraries, you can use the mojo copy-dependencies.

    Hope it can be useful in your case (examples)

    0 讨论(0)
  • 2020-11-28 18:45

    Create a repository folder under your project. Let's take

    ${project.basedir}/src/main/resources/repo
    

    Then, install your custom jar to this repo:

    mvn install:install-file -Dfile=[FILE_PATH] \
    -DgroupId=[GROUP] -DartifactId=[ARTIFACT] -Dversion=[VERS] \ 
    -Dpackaging=jar -DlocalRepositoryPath=[REPO_DIR]
    

    Lastly, add the following repo and dependency definitions to the projects pom.xml:

    <repositories>
        <repository>
            <id>project-repo</id>
            <url>file://${project.basedir}/src/main/resources/repo</url>
        </repository>
    </repositories>
    
    <dependencies>    
        <dependency>
            <groupId>[GROUP]</groupId>
            <artifactId>[ARTIFACT]</artifactId>
            <version>[VERS]</version>
        </dependency>
    </dependencies>
    
    0 讨论(0)
  • 2020-11-28 18:45

    None of the solutions work if you are using Jenkins build!! When pom is run inside Jenkins build server.. these solutions will fail, as Jenkins run pom will try to download these files from enterprise repository.

    Copy jars under src/main/resources/lib (create lib folder). These will be part of your project and go all the way to deployment server. In deployment server, make sure your startup scripts contain src/main/resources/lib/* in classpath. Viola.

    0 讨论(0)
提交回复
热议问题