无法添加此项目,因为它不使用Ant脚本生成JAR文件 [英] This project cannot be added because it does not produce a JAR file using an Ant script

查看:101
本文介绍了无法添加此项目,因为它不使用Ant脚本生成JAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注此处提问我现在想出了这个问题。
我正在使用NetBeans 8.

Following my question here I now came up to this problem. I'm using NetBeans 8.

我创建了一个Maven项目,我们称之为MyLibMaven,(我使用了New Project - > Maven - > Java应用程序)我移动了我的库,让我们称它为MyLib,进入这个Maven项目。

I've created a Maven Project, let's call it MyLibMaven, (I used New Project -> Maven -> Java Aplication) and I moved my library, let's call it MyLib, into this Maven Project.

现在当我进入正常的Java项目(让我们称之为MyProject)和我尝试将MyLibMaven作为库添加到MyProject我在Netbeans中获取此弹出窗口说:

Now when I go to my normal Java Project (let's call it MyProject) and I try to add MyLibMaven as a library to MyProject I get this popup in Netbeans saying:

This project cannot be added because it does not produce a JAR file using an Ant script

我在这里做错了什么?

这是我的pom.xml

Here's my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.dwnz.my.lib</groupId>
    <artifactId>MyLib</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    <name>MyLib</name>

    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>17.0</version>
        </dependency>
    </dependencies>
</project>

////////////////// ///////编辑//////////////////////////////

我将项目移动到maven项目并将MyLibMaven添加为依赖项。但是现在当我尝试运行我的项目时,我得到了这个失败的错误:

I moved my project to a maven project and added the MyLibMaven as a dependency. But now when I try to run my project I get this failed error:

--- exec-maven-plugin:1.2.1:exec (default-cli) @ TeseMaven ---
Could not load the icon: /view/images/enable-server-icon.png
Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at view.toolbar.ToolBar.createIcon(ToolBar.java:171)
    at view.toolbar.ToolBar.<init>(ToolBar.java:53)
    at view.MainFrame.<init>(MainFrame.java:98)
    at view.MainFrame.newInstance(MainFrame.java:586)
    at view.Main.main(Main.java:98)
------------------------------------------------------------------------

------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.382s
Finished at: Wed Jul 23 02:13:22 BST 2014
Final Memory: 5M/126M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project MyProjectMaven: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


推荐答案

您遇到的主要问题是......

The main problems you are having is...


  1. 将Netbeans项目作为库添加到现有Netbeans项目仅适用于Netbeans Project(ant)项目类型。

  2. 您需要将Maven项目中生成的Jar及其所有依赖项添加到Netbeans项目中。由于Netbeans(Ant)项目无法解析依赖项,因此必须手动解析这些依赖项并将每个Jar文件添加为库条目。

  3. 您的Maven项目仅生成Jar为您的项目,它不包括项目依赖项中的类/ jar。

您至少有两个基本选项.. 。

You have at least two basic options...

指示Maven在构建过程中包含所有依赖项。有(至少)两种方法来实现这一目标。您可以将所有类包含到单个Jar中,或者让Maven将所有依赖项复制到指定位置并更新 class-path 清单条目。

Instruct Maven to include all the dependencies as part of the build process. There are (at least) two ways to achieve this. You can include all the classes into a single Jar or have Maven copy all the dependencies to a specified location and update the class-path manifest entry.

我个人更喜欢第二种选择,但这是个人的事情。作为我的Maven构建过程的一部分,我包含以下内容......

I, personally, prefer the second option, but that's a personal thing. As part of my Maven build process, I include the following...

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <!--mainClass>com.acme.MainClass</mainClass-->
                    </manifest>
                </archive>
            </configuration>
        </plugin>        

基本上,第一个插件将所有依赖项Jars复制到 lib $ {project.build.directory} 中的code>目录。这是个人的事情,但我不喜欢将Jar的内容合并到一个主Jar中,因为我倾向于使用与我在项目中用作查找的相同名称的资源...

Basically, the first plugin copies all the dependency Jars to the lib directory in the ${project.build.directory}. This is a personal thing, but I don't like merging the contents of the Jar into a single "master" Jar, as I tend to have resources with the same name which I uses as lookups in my project...

第二个插件包含清单文件中的 class-path 元素,这可确保相关的jar包含在类中运行时加载器查找路径...

The second plugin includes the class-path element within the manifest file, this ensures that the dependent jars are included in the class loader lookup path at run time...

如果要创建单个Jar,请查看在Maven的jar中包含依赖项

If you want to create a "single" Jar, take a look at Including dependencies in a jar with Maven

将您的第二个项目作为Maven项目,并将您的第一个项目作为依赖项包含在内。然后,Maven将自动为您解析所有依赖项。这有点......

Make your second project a Maven project and include your first project as a dependency to it. Maven will then resolve all the dependencies automatically for you. That's kind of the point...

这篇关于无法添加此项目,因为它不使用Ant脚本生成JAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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