NetBeans无法找到我的Maven依赖项

时间:2017-06-23 14:21:44

标签: java maven netbeans

我创建了一个Maven项目,并添加了我所需的依赖项。当我尝试构建项目时,出现以下错误:

enter image description here

我的依赖关系确实显示org.apache.poi库在那里:

enter image description here

其中包括必备软件包:

enter image description here

以下是我的包含:

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;

我对Java相对较新,对Maven来说很新,但是当我右键单击时 DependenciesAdd Dependency,我输入相应的groupID和ArtifactID及版本(as listed in Maven Central),然后自动下载文件。不确定我还缺少什么。任何帮助表示赞赏。

编辑:我应该注意到我也尝试过手动安装工件并得到相同的结果。

编辑:这是我的pom.xml文件的依赖项部分。我很好奇为什么maven只增加了两个,当我有更多的lib时,但这似乎是另一个问题。这里列出了POI,它是编译器抱怨的那个。

<dependencies>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.16</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.16</version>
        <type>pom</type>
    </dependency>
</dependencies>

4 个答案:

答案 0 :(得分:1)

因此,解决方案仍然是解决方案,因为奇怪且特定于站点的解决方案。基本上就是这样的情况:我在一家普通开发人员都在其开发环境中使用Windows的公司工作。它们具有特定的配置,允许它们穿过公司代理,以便它们可以访问外部maven存储库,这些配置不是其他人拥有的。因此,Eclipse(这里的普通IDE)等工具无法通过代理下载。作为以前的Linux系统管理员,我能够在Linux VM中使用NetBeans解决代理问题。然而,问题是我使用的所有maven配置都是基于Windows的,这是我最终在settings.xml文件中修复的内容:

<localRepository>c:\.m2\repository</localRepository>

应该是

<localRepository>.m2/repository</localRepository>
在Linux中

。一旦我注意到了,并且更改了设置(和目录名称),它每次都能完美运行。感谢所有回复的人。

答案 1 :(得分:1)

有时,在编辑pom时Netbeans会感到困惑,并且无法从maven下载。只需对项目进行“清理并构建”,它将下载依赖项。

答案 2 :(得分:0)

尝试使用import org.apache.*;并删除所有手动导入。以防万一...

此外,请确保您使用此site

中的相关信息

我使用您的依赖项从Eclipse进行了测试,使用Maven clean配置并成功运行

答案 3 :(得分:0)

缺少信息

到目前为止,我在环境中发布的配置没有错误。我觉得它与你的类路径和/或Netbeans 非类路径依赖有关,但我无法确定,因为我没有必要的项目可见性。 GUI是否将var path = require('path'); var resolve = path.resolve; var AssetsPlugin = require('assets-webpack-plugin'); var WebpackCleanupPlugin = require("webpack-cleanup-plugin"); 'use strict'; var babelOptions = { "presets": [ [ "es2015", { "modules": false } ], "es2016" ] }; module.exports = [{ cache: true, context: resolve('Scripts'), devtool: "source-map", entry: { site: './site.ts', }, output: { path: path.resolve(__dirname, './dist/scripts'), filename: '[name].bundle.js', }, module: { rules: [{ test: /\.ts$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: babelOptions }, { loader: 'ts-loader' } ] }, { test: /\.js$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: babelOptions } ] }] }, plugins: [ new AssetsPlugin({ path: path.resolve(__dirname, './dist/assets') }), new WebpackCleanupPlugin({}) ], }]; 元素添加到您的POM.xml中?

因此,我不会试图通过问题和答案来发现您遇到的问题,而是会发布一个标准方法来设置此项目供您比较。

创建新项目

  1. 转到文件
  2. 新项目
  3. 类别 Maven
  4. 项目 Java应用程序
  5. 您将看到以下屏幕。

    New Java Application

    1. 保留默认设置,然后单击“完成”。您的项目现在应该具有以下结构

    2. enter image description here

      1. 右键单击依赖项文件夹,然后单击“添加依赖项”。输入以下信息。

      2. enter image description here

        1. 使用此信息再次执行以下操作

        2. enter image description here

          1. 您的项目现在应该如下所示

          2. enter image description here

            1. 转到文件,新文件,Java类

            2. 创建一个新类

              enter image description here

              1. 输入以下代码/

              2. 您是否在导入下看到一条红线?

                <type>

                右键单击您的项目,清理并构建。它会产生错误吗?如果是这样,你可以发布你的控制台吗?

相关问题