我已成功将JAR安装到Maven本地存储库中。我编辑我的pom.xml以包含这些行:
<dependency>
<groupId>org.jcrontab</groupId>
<artifactId>jcrontab</artifactId>
<version>4.0.0</version>
<scope>system</scope>
<systemPath>[somepath]/jcrontab-4.0.0.jar</systemPath>
</dependency>
但是,在使用install:install-file
安装后,我认为这些行是多余的。我只是用它们来安装,当我想“使用”jar时,它们没用,因为jar在本地仓库中。
所以我把它们改成了:
<dependency>
<groupId>org.jcrontab</groupId>
<artifactId>jcrontab</artifactId>
<version>4.0.0</version>
</dependency>
与远程Maven中央存储库中存在的那些依赖项相同的形式。但现在Eclipse抱怨:
missing artifact: org.jcrontab:jcrontab:jar:4.0.0
在Java Build路径的Maven依赖库中,我在jar上看到了红十字,说:
jcrontab-4.0.0.jar - D:\ desarrollo \ eclipse-jee-mars-x86_64 \ eclipse \ $ {maven.home} \ m2 \ repository \ org \ jcrontab \ jcrontab \ 4.0.0(缺失)< / p>
在这个目录下,我只看到:
jcrontab-4.0.0.jar.lastUpdated jcrontab-4.0.0.pom.lastUpdated
那里没有罐子。但是这个Eclipse repo中的其他依赖项jar就在他们的位置。
当我检查我的maven home repo(<maven-installation-dir>/m2/repository
)时,那里安装了jar。但是在Eclipse目录下的repo中,jar丢失了。
我很困惑。
如果外部jar的安装在Maven安装repo下生成JAR,为什么Eclipse“Maven依赖”库指向Eclipse目录下的repo? {$maven.home}
目录对我来说很难闻。
我是否应该像我所做的那样更改本地安装的jar的依赖项?
根据建议,我执行install:install-file命令,然后执行:
C:\Windows\System32>mvn install:install-file -Dfile="D:\desarrollo\Java environment\lib\jcrontab-4.0.0.jar" -DgroupId=org.jcronta
b -DartifactId=jcrontab -Dversion=4.0.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing D:\desarrollo\Java environment\lib\jcrontab-4.0.0.jar to D:\desarrollo\Java environment\lib\Maven\apache-maven-3.5.0\bin\..\m2\repository\org\jcrontab\jcrontab\4.0.0\jcrontab-4.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.597 s
[INFO] Finished at: 2017-08-03T14:27:48+02:00
[INFO] Final Memory: 6M/114M
[INFO] ------------------------------------------------------------------------
答案 0 :(得分:0)
与远程Maven中央存储库中存在的依赖项相同的表单。
但是jcrontab并不存在于maven中心。
在maven central上看到自己:https://search.maven.org/#search|ga|1|jcrontab
因此,如果要将jar用作另一个依赖项,则需要将jar安装到本地存储库中。你可以这样做:
mvn install:install-file -Dfile=jcrontab-4.0.0.jar -DgroupId=org.jcrontab -DartifactId=jcrontab -Dversion=4.0.0 -Dpackaging=jar
另请参阅此处的maven文档:https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html