`
movingboy
  • 浏览: 55621 次
社区版块
存档分类
最新评论

maven的<systemPath>的误用一例及解决办法

阅读更多
手上一个工程使用maven来构建,POM.xml中有如下内容:

引用
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
<scope>system</scope>
<systemPath>${basedir}/ext_lib/ojdbc6.jar</systemPath>
</dependency>


使用maven 3.3.9来run的时候报错:

引用
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.kingsoft:passport3:jar:1.0.0
[WARNING] 'dependencies.dependency.systemPath' for com.oracle:ojdbc:jar should not point at files within the project directory, ${basedir}/ext_lib/ojdbc6.jar will be unresolvable by dependent projects @ line 212, column 16
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]


引用
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.0.RELEASE:run (default-cli) on project passport3: An exception occured while running. null: InvocationTargetException: Error creating bean with name 'mybatisConfig': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource com.kingsoft.passport3.config.MybatisConfig.dataSource;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception;
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active). -> [Help 1]


搜了下,在http://stackoverflow.com/questions/3642023/having-a-3rd-party-jar-included-in-maven-shaded-jar-without-adding-it-to-local-r找到原因如下:

引用
because the system scoped dependencies are assumed to be always present (this is exactly what the system scope is about) so they won't be included.

system: This dependency is required in some phase of your project's lifecycle, but is system-specific. Use of this scope is discouraged: This is considered an "advanced" kind of feature and should only be used when you truly understand all the ramifications of its use, which can be extremely hard if not actually impossible to quantify. This scope by definition renders your build non-portable. It may be necessary in certain edge cases. The system scope includes the <systemPath> element which points to the physical location of this dependency on the local machine. It is thus used to refer to some artifact expected to be present on the given local machine an not in a repository; and whose path may vary machine-to-machine. The systemPath element can refer to environment variables in its path: ${JAVA_HOME} for instance.

So, instead of using the system scope, either:

    Add your libraries to your local repository via install:install-file. This is a quick and dirty way to get things working, it might be an option if you're alone but it makes your build non portable.
    Install and run an "enterprise repository" like Nexus, Archiva, or Artifactory and add your libraries via deploy:deploy-file. This is the ideal scenario.
    Setup a file based repository as described in this previous answer and put your libraries in there. This is the best compromise if you don't have a corporate repository but need to work as a team and don't want to sacrifice portability.


最后的解决办法是:

1 改写POM.xml中的dependency为如下内容:

引用
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
</dependency>


2 增加如下plugin:

引用
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.5.2</version>
      <executions>
        <execution>
          <id>install-external</id>
          <phase>clean</phase>
          <configuration>
            <file>${basedir}/ext_lib/ojdbc6.jar</file>
            <repositoryLayout>default</repositoryLayout>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc</artifactId>
            <version>6</version>
            <packaging>jar</packaging>
            <generatePom>true</generatePom>
          </configuration>
          <goals>
            <goal>install-file</goal>
          </goals>
        </execution>
      </executions>
    </plugin>


3 运行mvn clean和mvn install

至此问题解决。
分享到:
评论

相关推荐

    maven 配置详解

    &lt;parent&gt; &lt;!--被继承的父项目的构件标识符 --&gt; &lt;artifactId /&gt; &lt;!--被继承的父项目的全球唯一标识符 --&gt; &lt;groupId /&gt; &lt;!--被继承的父项目的版本 --&gt; &lt;version /&gt; &lt;!-- 父项目的pom.xml...

    Maven之远程仓库的配置详解

    除此之外,`&lt;repository&gt;`还可以包含`&lt;releases&gt;`和`&lt;snapshots&gt;`子元素,用于控制Maven下载不同版本构件的行为: - `&lt;releases&gt;`:定义Maven处理发布版本构件的策略,如是否启用下载、更新频率等。 - `&lt;snapshots&gt;...

    人大金仓驱动包kingbasejdbc.jar V8.6.0、8.8.0驱动jar包

    &lt;systemPath&gt;${basedir}/src/main/resources/jar/kingbase8-8.6.0.jar&lt;/systemPath&gt; &lt;/dependency&gt; jdbc driver-class-name: com.kingbase8.Driver url: jdbc:kingbase8://127.0.0.1:54321/template1?...

    KKfile文件上传依赖aspose-cad-23.7.jar

    注释掉原有的aspose依赖,将下载文件挡在lib文件夹下,并在pom文件中添加新的依赖。&lt;dependency&gt; &lt;groupId&gt;com.aspose.cad&lt;/... &lt;systemPath&gt;${project.basedir}/lib/aspose-cad-23.7.jar&lt;/systemPath&gt; &lt;/dependency&gt;

    maven tomcat7改造后插件

    &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;configuration&gt; &lt;path&gt;/&lt;/path&gt; &lt;port&gt;9001&lt;/port&gt; &lt;staticContextPath&gt;/img&lt;/staticContextPath&gt; ...

    Maven使用tomcat8-maven-plugin插件的详细教程

    &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;version&gt;2.2&lt;/version&gt; &lt;/plugin&gt; 并没有找到tomcat8-maven-plugin的plugin,在Maven的中央仓库中根本就没有这个...

    ojdbc6(此包解决mybatis_plus查询时分秒为0问题).7z

    ojdbc6(此包解决mybatis_plus查询时分秒为0问题),springboot项目+oracle11g就用这个jdbc就行,放在项目的resources目录... &lt;systemPath&gt;${pom.basedir}/src/main/resources/lib/ojdbc6.jar&lt;/systemPath&gt; &lt;/dependency&gt;

    <<Maven实战>>高清完整版pdf

    &lt;&lt;Maven实战&gt;&gt;高清完整版pdf,相信对大家使用Maven有很大的帮助

    <<Maven权威指南>>+<<Maven in Action>> pdf扫描版丛书

    Apache Maven 是一个强大的Java项目管理工具,它简化了构建、依赖管理和项目信息管理的过程。《Maven权威指南》和《Maven in Action》是两本深入解析Maven的书籍,对于初学者和进阶者来说,都是不可或缺的参考资料。...

    钉钉sdk-dependency-maven

    钉钉sdk-dependency-maven dingtalk 放到maven仓库的com目录路径下 &lt;dependency&gt; &lt;groupId&gt;DingTalk&lt;/groupId&gt; ...钉钉的无官方 &lt;dependency&gt; ,使用maven命令将jar打包成maven形式的&lt;dependency&gt;

    Maven引入本地Jar包并打包进War包中的方法

    &lt;systemPath&gt;${basedir}/lib/cpdetector_1.0.10.jar&lt;/systemPath&gt; &lt;/dependency&gt; ``` 配置Maven插件 在上述配置以后,我们已经可以在编写代码时引入Jar包中的类了。但是,在打包时,由于scope=system,默认并不会...

    maven依赖本地jar包

    使用`&lt;scope&gt;system&lt;/scope&gt;`和`&lt;systemPath&gt;`的方式,可以有效地将本地的JAR包纳入到Maven项目的依赖管理中。 #### 2. 安装本地JAR至本地仓库 另一种更为推荐的做法是将本地的JAR包安装到Maven的本地仓库中,通过...

    hadoop mapreduce wordcount

    &lt;systemPath&gt;${JAVA_HOME}/lib/tools.jar&lt;/systemPath&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;junit&lt;/groupId&gt; &lt;artifactId&gt;junit&lt;/artifactId&gt; &lt;version&gt;3.8.1&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/...

    eclipse更新maven,jdk改变解决办法

    eclipse更新maven,jdk改变解决办法 eclipse更新maven时,项目原本设定的jdk版本发生改变,这是由于maven的编译器插件的默认设置所致。编译器插件用来编译项目的源文件,从3.0版本开始,默认编译器是javax.tools....

    apt-maven-plugin:Maven APT插件

    &lt;groupId&gt;com.mysema.maven&lt;/groupId&gt; &lt;artifactId&gt;apt-maven-plugin&lt;/artifactId&gt; &lt;version&gt;1.1.3&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;goals&gt; &lt;goal&gt;process&lt;/goal&gt; &lt;/goals&gt; &lt;config

    Maven和Tomcat插件

    &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;version&gt;2.2&lt;/version&gt; &lt;configuration&gt; &lt;url&gt;http://localhost:8080/manager/text&lt;/url&gt; &lt;server&gt;TomcatServer...

    idea离线导入maven项目

    &lt;url&gt;file://D:/data-maven&lt;/url&gt; &lt;/mirror&gt; &lt;/mirrors&gt; ``` 同时,确保`&lt;offline&gt;`标签设置为`false`,这样Maven会尝试从配置的本地仓库获取依赖,而不是尝试在线下载。 3. **在IntelliJ IDEA中设置Maven** ...

    Maven使用tomcat8-maven-plugin插件.docx

    &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat8-maven-plugin&lt;/artifactId&gt; &lt;version&gt;3.0-r1655215&lt;/version&gt; &lt;/plugin&gt; ``` 但是,如果我们直接添加上面的依赖项,Maven 将无法找到该插件,...

    maven整合

    &lt;systemPath&gt;C:/Program Files/Java/jdk1.7.0_07/lib/tools.jar&lt;/systemPath&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/profile&gt; &lt;/profiles&gt; &lt;!-- 添加SSH框架相关的依赖 --&gt; &lt;dependencies&gt; &lt;dependency&gt; ...

    maven 远程部署tomcat

    &lt;path&gt;/spring3JDBC&lt;/path&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; ``` 对于 Tomcat 6: ```xml &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;tomcat-maven-...

Global site tag (gtag.js) - Google Analytics