对IntellijIDEA和Maven的问题 [英] Questions to IntellijIDEA and Maven

查看:169
本文介绍了对IntellijIDEA和Maven的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几年里,我一直在使用XCode和Objective-C,但我知道,一旦我必须转换到Java等项目的Eclipse项目。案例是,我并不特别喜欢Eclipse,这让我进入了一个新的开发环境,即IntellijIDEA。但是,我完全不熟悉如何处理文件以及如何添加外部库,也不知道我的CLASSPATH应该是什么。我在哪里将这些外部库保留在我的项目中?我也在使用Maven,我不太清楚为什么要使用依赖项。如果我在我的类路径中包含.jar - 或者我存储我的资源,类等等 - 为什么有依赖?我有一个工作项目,但我不习惯发布或使用它,而不完全确定我在那里做了什么。我理解如何在IntelliJ中添加外部.jar文件,但是我在哪里可以在项目中添加这些外部库?

I have been working in XCode and with Objective-C in the last few years, but I knew that once I would have to transition to Eclipse or the like for Java projects. Case is, I do not particularly like Eclipse, which led me to a new development environment, namely IntellijIDEA. However, I am not at all familiar with how I should handle my files and how to add external libraries, nor do I know what my CLASSPATH is supposed to be. Where do I keep these external libraries in my project? I am also working with Maven and I am not quite sure why to use dependencies. If I include the .jar in my Classpath - or whereever I store my resources, classes etc. - why are there dependencies ? I have got one working project, but I am not comfortable releasing or using it while not exactly sure what I have done there. I understand how I can add external .jar files in IntelliJ, but where do I add these external libraries in my project ?

这就是我到目前为止的做法:
假设我已经下载了一个Maven项目,我想在其他项目中使用它。我使用 mvn install 然后(在我的模块设置中)我将目标文件夹中的.jar添加为外部库。 IntelliJ是否保留对该.jar文件的引用?如果.jar在我的下载文件夹中并且我想将项目传输到服务器,这个连接是否已损坏?

This is how I have done it up to now: Let's say I have downloaded a Maven project and I would like to use it in some other project. I use mvn install and then (in my Module Settings) I add the .jar from the target folder as an external library. Does IntelliJ keep a reference to that .jar file ? If that .jar is in my Downloads folder and I would like to transfer the project to a server, is this connection broken ?

推荐答案

在Maven项目中,你在pom.xml文件中添加了你所依赖的库,有 no 需要将它们添加到IDE中的其他位置和/或通过IDE将它们链接到您的项目。只需在 pom.xml 文件中添加新的依赖项。

in a Maven project you add your libraries you depend on in your pom.xml file, there is no need to add them somewhere else in your IDE and/or link them via the IDE to your project. just add a new dependency to your pom.xml file.

maven商店(如果没有另外设置)文件夹中的所有工件(库):〜/ .m2 / ,这是您保留依赖项的地方,也是您的本地maven存储库。

maven stores (if not set otherwise) all the artifacts (libraries) in a folder: ~/.m2/, that is where you keep your dependencies, and which is your local maven repository.

Maven让您的生活更轻松,因为您不必再​​将jar添加到类路径中。确保您的maven项目确实被IDE识别为maven项目(通常在项目视图中只是一个小的 M )。

Maven makes your life easier as you do not have to add the jar's to your classpath anymore. make sure that your maven project is indeed recognized as a maven project by your IDE (usually it's a tiny M in your projects view).

这里是maven的简短介绍,一开始对我帮助很大: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html ,特别是为了理解生命周期。

here is a short intro to maven, that helped me a lot in the beginning: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html , especially in order to understand the lifecycle.

如你提到的那样 mvn install :你构建的工件将被部署到你的本地maven存储库,你拥有的所有其他项目都可以利用这个工件并将引用您部署的最新工件。

as you mentioned mvn install: the artifact you built will get deployed to your local maven repository, all other projects you have can make use of this artifact and will reference the latest artifact you deployed.

您可以像运行任何其他项目一样运行项目,单击运行按钮并选择你的主要课程。

you can run your project just as any other project, click on the run button and select your main class.

如果您的项目产生了一个可运行的jar,您也可以在 pom.xml 文件中定义它。请参阅如何创建具有依赖项的可执行JAR使用Maven?在一个jar中创建一个包含所有依赖项/库的jar,或者如何使用maven创建一个可运行的jar,其中包含一个单独的lib中的依赖项。文件夹(不是超级jar)是一个可运行的jar,它将deps / libs放在一个单独的文件夹中。无论如何,在两种情况下,Maven都会适当地生成 MANIFEST 文件(可执行jar所需)。

if your project results in a runnable jar, you can also define it in your pom.xml file. see How can I create an executable JAR with dependencies using Maven? to create a jar containing all your dependencies/libraries in one jar, or How to create a runnable jar with maven that includes dependencies in a separate "lib" folder (not an uber jar) for a runnable jar which puts the deps/libs to a separate folder. anyway, in both cases the MANIFEST file (which is needed for an executable jar) will be generated by Maven appropriately.

这篇关于对IntellijIDEA和Maven的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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