我有一个本地jar文件要导入我的文件夹,我已经运行了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文件夹中,我还可以看到生成了相应的文件:
在pom.xml文件中,我有:
<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更新项目。
然而,Eclipse仍然抱怨来自该依赖项的类api-core-1.0.0.jar无法解析为类型。
我错过了什么?
当错误持续时,maven的settings.xml文件已包含在行中。
<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设置是正确的:
答案 0 :(得分:1)
<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 /下创建,如果它不存在。
答案 1 :(得分:0)
转到Maven->conf->setting.xml
。添加<localRepository>The path to the local repository </localRepository>
如果您在c:
,那么路径应该如下<localRepository>C:\Users\usename\.m2\repository</localRepository>
答案 2 :(得分:0)
如果你正在使用eclipse试试这个。
希望这有帮助。