简体   繁体   English

在什么目录下放置maven项目的java库?

[英]In what directory to put java libraries for maven project?

I found that Maven implies specific directory layout. 我发现Maven意味着特定的目录布局。 But I don't understand from here: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html where java libraries needed to compile and run my code should be placed. 但我不明白这里: http//maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html应该放置编译和运行我的代码所需的java库。 I think they shouldn't be placed under 'src/main/resources' because resources is something like images or so. 我认为它们不应放在'src / main / resources'下,因为资源就像图像一样。 Also it doesn't look right to place them under 'src/main/java'. 将它们放在'src / main / java'下也不正确。 If I wouldn't use maven, I'd place libraries in project's root lib directory. 如果我不使用maven,我会将库放在项目的根lib目录中。 But I don't think that for maven project it will be right. 但我不认为对于maven项目来说这是对的。 Please advise. 请指教。

UPD: I solved the problem. UPD:我解决了这个问题。 The matter was that I set packages for my sources as src.main.myApp instead of main.myApp. 问题是我为我的源码设置了src.main.myApp而不是main.myApp。 This seems to upset maven. 这似乎让maven感到不安。

Maven handles your project dependencies in a different way to a 'Standard' Java project. Maven以与“标准”Java项目不同的方式处理项目依赖项。

You declare the libraries you depend on in your project's pom.xml: 您在项目的pom.xml中声明了您依赖的库:

eg 例如

<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>org.example</groupId>
    <artifactId>your-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>your-project-web</name>

    <dependencies>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.8.5</version>
        </dependency>
    </dependencies>     
</project>

When you use a maven command to build the project, ie mvn install , it will download the dependencies for you and store them in your local repository. 当您使用maven命令构建项目(即mvn install ,它将为您下载依赖项并将它们存储在本地存储库中。

In Maven, you do not keep libraries in your project. 在Maven中,您不会在项目中保留库。 You specify dependencies on these libs, and they get populated into your local repository. 您可以在这些库中指定依赖项,并将它们填充到本地存储库中。 At the time of build, if you are packaging the libs (say for a war file), they do get pulled into target//WEB-INF/lib. 在构建时,如果要打包lib(比如war文件),它们会被拉入目标// WEB-INF / lib。 But in general, the whole idea is not to deal with these libraries or manage them, just to manage dependencies in your pom file, and forget the rest. 但总的来说,整个想法不是处理这些库或管理它们,只是为了管理pom文件中的依赖项,而忘记其余的。

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

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