Maven的编译无法识别我的本地回购依赖 [英] maven compile does not recognize my local repo dependency

查看:94
本文介绍了Maven的编译无法识别我的本地回购依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地jar文件要导入到我的文件夹中,并且我已经运行了mvn install:

I have a local jar file to import into my folder, and I have run the mvn install:

mvn install:install-file -Dfile="C:\myapp\Development\core\target\api-core-1.0.0.jar" -DgroupId="com.myapp" -DartifactId="api-core" -Dversion="1.0.0" -Dpackaging=jar

这是成功的:

------------------------------------------------------------------------
[INFO] Building api-malloc 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ api-malloc ---
[INFO] Installing C:\myapp\Development\core\target\api-core-1.0.0.jar to C:\Users\myname\.m2\repository\com\myapp\api-core\1.0.0\api-core-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

从.me文件夹中,我还可以看到生成了相应的文件:

From the .me folder, I can also see that the appropriate files are generated:

在pom.xml文件中,我有:

In the pom.xml file, I have:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myapp</groupId>
    <artifactId>api-malloc</artifactId>
    <version>0.0.1</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.myapp</groupId>
            <artifactId>api-core</artifactId>
            <version>1.0.0</version>
        </dependency>
        ... rest of dependencies
    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                        <addClasspath>true</addClasspath>
                         </manifest>
                         <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <webResources>
                         <webResource> 
                           <directory>${project.build.directory}/WebContent/WEB-INF</directory> 
                           <includes> 
                             <include>web.xml</include> 
                           </includes> 
                           <targetPath>WEB-INF</targetPath> 
                           <filtering>true</filtering> 
                         </webResource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                    <id>copy-dependencies</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                            <outputDirectory>${project.build.directory}/WebContent/WEB-INF/lib</outputDirectory>
                            <includeScope>runtime</includeScope>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

安装jar文件后,我还做了一个maven更新项目.

I also did a maven update project after installing the jar file.

但是Eclipse仍然抱怨无法将依赖项api-core-1.0.0.jar中的类解析为一种类型.

However Eclipse still complain about the classes from that dependency api-core-1.0.0.jar cannot be resolved to a type.

我想念什么?

在错误仍然存​​在的情况下,行中已经包含了maven的settings.xml文件.

The maven's settings.xml file is already included the lines while the error persist.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>C:/Users/username/.m2/repository</localRepository>
  <offline>false</offline>

在Eclipse中,maven设置是正确的:

And in Eclipse, the maven setting is correct:

推荐答案

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <localRepository>${userhome}/.m2/repository</localRepository>
      <offline>false</offline>
</settings>

尝试将其添加到settings.xml 在$ {userhome}/.m2/下创建(如果不存在).

try to add this to settings.xml Create on under ${userhome}/.m2/ if it does not exists.

这篇关于Maven的编译无法识别我的本地回购依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆