简体   繁体   English

NetBeans和Maven项目

[英]NetBeans and Maven Project

Hello i have a maven project build in netbeans. 您好,我在netbeans中构建了一个Maven项目。

issue i having is i have some external dependencies jar libraries that i need to make my source file work. 我遇到的问题是我需要一些外部依赖项jar库,以使源文件正常工作。

example: on my source code import org.cloudme.puppet ( which i have a jar for ) 示例:在我的源代码上,导入org.cloudme.puppet(我有一个jar)

now in java project for net means i have "library" where you can right click and "add jar/folder" 现在在网络的Java项目中,我有一个“库”,您可以在其中单击鼠标右键并“添加jar /文件夹”

with the maven project i do not have that, i have a " Dependencies " folder ,, which will NOT let me right click and add JAR* 在Maven项目中,我没有这个,我有一个“ Dependencies”文件夹,该文件夹不会让我右键单击并添加JAR *

so how can i bring them in ? 那我怎么带他们进来? how can i get my source code to find those dependencies ? 我如何获取我的源代码来查找那些依赖项?

i have tried .. i even created a new java class project, but that cannot be picked up my main project. 我已经尝试过..我什至创建了一个新的Java类项目,但是无法将其放在我的主项目中。

please help, any direction will help 请帮助,任何方向都将帮助

You have two options. 您有两个选择。

1. Use the Maven query tool to find the Group/Artifact/Version you're looking for and add it directly to your pom.xml file. 1.使用Maven查询工具找到您要查找的Group / Artifact / Version,然后将其直接添加到pom.xml文件中。

The preferred way of getting your dependencies onto the classpath of your Maven project would be to add the maven artifact corresponding to your import to your project's pom.xml file. 将依赖项添加到Maven项目的类路径的首选方法是将与导入对应的Maven工件添加到项目的pom.xml文件中。 In NetBeans, you can do this easily by right-clicking the Dependencies folder of your Maven project in the Projects view and choosing "Add Dependency". 在NetBeans中,可以通过在“ Projects视图中右键单击Maven项目的Dependencies文件夹,然后选择“添加依赖项”来轻松实现此目的。 This will bring up a query tool that will allow you to search your maven repositories (configured in the settings.xml of your .m2 folder) for org.cloudme.puppet or any other package/class name you require. 这将打开一个查询工具,使您可以在Maven存储库(在.m2文件夹的settings.xml中配置)中搜索org.cloudme.puppet或所需的任何其他包/类名称。 If NetBeans can't find the correct GroupID/Artifact ID/Version for the packages/classes you're looking for, you can visit search.maven.org and perform a similar query against an internet-visible maven repository. 如果NetBeans找不到所需包/类的正确GroupID /工件ID /版本,则可以访问search.maven.org并针对Internet可见的Maven存储库执行类似的查询。 I've found about 90% of everything I've ever needed there - it's a great resource. 我已经找到了我所需要的一切的90%-这是一个很好的资源。

2. Manually create a subfolder in your project for your jars, then add them to your pom.xml file as "system" dependencies. 2.在您的项目中为jar手动创建一个子文件夹,然后将它们作为“系统”依赖项添加到pom.xml文件中。

This answer will make Maven purists really upset ... but sometimes the class you're trying to import simply doesn't exist as a maven project, and you have to use a raw Jar file because you don't have source code. 这个答案将使Maven纯粹主义者感到不安...但是有时候您要导入的类根本不存在于maven项目中,并且您必须使用原始的Jar文件,因为您没有源代码。 If this is the case, you'll want to add it to your project in its own "lib" folder (or whatever you choose to call it), then add it to your pom.xml dependency list as a system dependency. 在这种情况下,您需要将其添加到项目中自己的“ lib”文件夹(或任何您选择调用的文件夹)中,然后将其作为system依赖项添加到pom.xml依赖项列表中。 For more info on configuring system dependencies in Maven, look here: 有关在Maven中配置系统依赖项的更多信息,请参见此处:

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies

You have to have an appropriate <dependencies> section in your pom.xml that contains the artifacts (jars) your project relies on, ie its dependencies. 您必须在pom.xml中有一个适当的<dependencies>部分,其中包含项目所依赖的工件(jar),即其依赖项。 See Introduction to the Dependency Mechanism . 请参阅依赖机制简介

org.cloudme.puppet isn't available in Maven's Central Repository and I'm not sure whether it's available in any other remote repository. org.cloudme.puppet在Maven的中央存储库中不可用,我不确定在其他任何远程存储库中是否可用。

If you have the jar of your project's dependency you can install it into your local repository with the install:install-file goal. 如果您具有项目依赖项的jar,则可以使用install:install-file目标将其安装到本地存储库中。

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

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