Maven: Add local dependencies to jar

前端 未结 4 1751
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 21:25

I have a dependency

    
        de.matthiasmann
        twl
        &         


        
相关标签:
4条回答
  • 2020-12-31 21:29

    YOu can implement this in many ways refer the blog below

    http://blog.valdaris.com/post/custom-jar/

    0 讨论(0)
  • 2020-12-31 21:36

    You cannot use systemPath, unless your Java EE server/container has that jar configured.

    Remember that maven is development and compile time only. Once the war file is built, maven has no effect except for having placed all the desired jars into the WEB-INF/lib folder.

    When you specify system scope, it means that it is your responsibility to ensure that the jar is present when the war is deployed. You already have a framework to do that and you do not wish to encumber your build dependency with that jar, but you have to make it available thro Maven only during development.

    The other similar scope is "provided". e.g., JBoss or your corporate common deployment Tomcat framework already provides many of the jars like Spring and Hibernate that are loaded by the server startup and common to all apps in the server. Therefore, you would not want maven build to include those into the war file.

    The right way, Maven gurus would tell you. is to have your own maven server and build whatever artefacts you need into that server. However, occasionally that is not possible.

    Therefore, on such occasions, I create project level repository that is distributed with the project and checked into version control. I run the command mvn install to create a project level directory called, say, "project-repo".

    http://maven.apache.org/plugins/maven-install-plugin/examples/specific-local-repo.html (Due to familiarity, most of the time, I build the repo by hand rather than run mvn install).

    Then in the POM, I specify file://${project.basedir}/project-repo as one of the repositories. The caveat with this is that in Windows, the slashes other than the pair after "file://" has to be back-slashes when referring to Windows file system paths.

      <repositories>
        <repository>
          <id>my-repo1</id>
          <name>my custom repo</name>
          <url>http://ho.ho.ho</url>
        </repository>
        <repository>
          <id>project-repo</id>
          <name>my project repo</name>
          <url>file://${project.basedir}\project-repo</url>
        </repository>
      </repositories>
    
    0 讨论(0)
  • 2020-12-31 21:48

    See Maven 2 assembly with dependencies: jar under scope "system" not included for why system dependencies are not included and how you can work around it, specifically the mvn install:install-file code is what you want.

    0 讨论(0)
  • 2020-12-31 21:55

    If you have such an dependency the best solution is first to use a repository manager and simply put that dependency into the repository manager and afterwards use it as simple dependency.

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