Tim S.
Tim S.

Reputation: 2257

NetBeans cannot find my Maven dependency

I have created a Maven project, and have added my required dependencies. When I attempt to build the project, I get the following errors:

enter image description here

My dependencies do show that the org.apache.poi library is there:

enter image description here

Which includes the requisite packages:

enter image description here

Here are my includes:

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;

I'm relatively new to Java, and very new to Maven, but when I right click on Dependencies and Add Dependency, I enter the appropriate groupID and ArtifactID and version, (as listed in Maven Central) and it automatically downloads the file. Not sure what else I'm missing. Any help is appreciated.

Edit: I should note that I also tried Manually installing artifact and got the same result.

Edit: Here's the dependency section of my pom.xml file. I'm curious why maven only added two, when I have many more libs, but that seems to be another issue. POI is listed here and it's the one that the compiler is complaining about.

<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>

Upvotes: 1

Views: 12699

Answers (4)

Lorenzo
Lorenzo

Reputation: 61

Sometimes Netbeans gets confused as you are editing the pom and doesn't download from maven. Simply do a "clean and build" of your project and it will download the dependency.

Upvotes: 2

Tim S.
Tim S.

Reputation: 2257

So the solution, as odd and site-specific as it is, is still the solution. Basically here's the situation: I'm working at a company where the normal developers all use Windows for their development environments. They have specific configurations that allow them to punch through the corporate proxy so they can get to external maven repositories, configurations that not everyone else has. Because of this, tools like Eclipse (the normal IDE here) was not able to download through the proxy. Being a former Linux sysadmin, I was able to get the proxy issues resolved using NetBeans in a Linux VM. The issue, however was that all of the maven configs that I used were based in windows, and this is what I finally fixed in my settings.xml file:

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

should have been

<localRepository>.m2/repository</localRepository>

in Linux. Once I noticed that, and changed the settings (and directory name) it worked flawlessly every time. Thanks to all who responded.

Upvotes: 2

Chris Maggiulli
Chris Maggiulli

Reputation: 3834

Missing information

There is no error with the configurations you have posted thus far in my environment. I have a feeling it has to do with your class path and/or Netbeans Non-classpath dependencies however I cannot be sure because I do not have the necessary visibility into your project. Did the GUI add the <type> element to your POM.xml?

Therefore instead of trying to uncover the issue you are experiencing via question and answer I will posted a standard way to set up this project for you to compare against.

Create new project

  1. Go to File
  2. New Project
  3. Categories Maven
  4. Projects Java Application

You will get the following screen.

New Java Application

  1. Leave the defaults as they stand for now and click finish. Your project should now have the following structure

enter image description here

  1. Right click on the dependency folder and click Add Dependency. Enter the following information.

enter image description here

  1. Do the following again with this information

enter image description here

  1. Your project should now look like this

enter image description here

  1. Create a new class by going to File, New File, Java Class

enter image description here

  1. Enter the following code/

Do you see a red line under your import?

package com.mycompany.mavenproject1;
import org.apache.poi.*;
public class Main {
    public static void main(String[] args) {

    }
}

Right click on your project, clean and build. Does it generate an error? If so can you post your console?

Upvotes: 2

Qehu
Qehu

Reputation: 145

Try to use import org.apache.*; and remove all your manual imports. Just in case...

Furthermore, make sure that you're using dependency info from this site

I did a test from Eclipse with your dependency, using Maven clean configuration and run successfully

Upvotes: 0

Related Questions