简体   繁体   English

Maven看不到的本​​地安装的jar

[英]Locally installed jar not seen by maven

I have source code for a framework, let's call it my-framework . 我有一个框架的源代码,我们称它为my-framework It provides various packages, including com.not_telling.framework.db . 它提供了各种软件包,包括com.not_telling.framework.db

I have a pom.xml file for this framework: 我为此框架提供了一个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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.not_telling</groupId>
    <artifactId>my-famework</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>my-framework Maven Library</name>
    <url>http://maven.apache.org</url>
    <!-- more things here... -->
</project>

I can compile this and install it to my local repository cache, using this command: 我可以使用以下命令对其进行编译并将其安装到本地存储库缓存中:

mvn install

End of the install log: 安装日志结束:

[INFO] Installing C:\Users\MyUserName\my-framework\backend\target\my-framework.jar to C:\Users\MyUserName\.m2\repository\com\not_telling\my-famework\0.0.1-SNAPSHOT\my-famework-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\MyUserName\my-framework\backend\pom.xml to C:\Users\MyUserName\.m2\repository\com\not_telling\my-famework\0.0.1-SNAPSHOT\my-famework-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Then I have another project, that tries to use this as a dependency: 然后,我有另一个项目,试图将其用作依赖项:

    <dependency>
        <groupId>com.not_telling</groupId>
        <artifactId>my-famework</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

The compilation phase of this project fails with this message: 该项目的编译阶段失败,并显示以下消息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-project: Compilation failure: Compilation failure:
[ERROR] /C:/Users/MyUserName/workspace/my-project/backend/src/main/java/com/not_telling/some_example.java:[13,17] package com.not_telling.framework.db does not exist

Why is that? 这是为什么? Maybe because the jar is in the repository cache, but not in a local repository? 也许是因为jar位于存储库缓存中,而不是本地存储库中?

This question is a follow up of absolute maven pomderived entry added to classpath - I realized that instead of doing magic with relative source directory references, I need to make a separate module, but I'm facing this problem. 这个问题是添加到classpath绝对maven pomderived条目的跟进-我意识到,除了对相对的源目录引用进行魔术处理之外,我需要制作一个单独的模块,但是我面临着这个问题。

It was bleeding from numerous wounds. 它从无数伤口流血。 These needed to be fixed: 这些需要修复:

  • move source files from under src/ to under src/main/java, in both the framework and the application project 在框架和应用程序项目中将源文件从src /下移动到src / main / java下
  • change the group and the artifact id to match the package name Eg for a package that is named "com.not_telling.framework" I had to use groupId=com.not_telling and name=framework. 更改组和工件ID以匹配名为“ com.not_telling.framework”的软件包的软件包名称,例如,我必须使用groupId = com.not_telling和name = framework。
  • The dependency scope was wrong in the application's pom file. 应用程序的pom文件中的依赖项范围错误。 I had to remove test 我必须删除测试

Now it works from command line I can do "mvn install" for the framework, and then "mvn package" for the applications. 现在它可以从命令行运行,我可以为框架执行“ mvn install”,然后为应用程序执行“ mvn package”。

The only problem left is that the application cannot be compiled from eclipse, I had to remove all linked source folders / build paths in the application project to the framework. 剩下的唯一问题是无法从Eclipse中编译应用程序,我不得不删除应用程序项目中所有链接到源文件夹/构建路径的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM