Buszman Buszman - 1 year ago 210
Java Question

The declared package does not match the expected package for apache-commons

I'm trying to add apache-commons to my fresh project but I got problems with packages after importing the source.

The declared package "org.apache.commons.math" does not match
the expected package "src.main.java.org.apache.commons.math"

What can I do?

Answer Source

Packages in Java translate into a folder hierarchy, both for the source files and the compiled class files. A Source Folder expected to contain the package org.apache.commons.math will contain files in a structure like org/apache/commons/math/ where the Source Folder is the direct parent of org. Having an expected package of src.main.java.org.apache.commons.math means that src/main/java is in a Source Folder rather that being set as a Source Folder. Open your project's Properties dialog, go to the Java Build Path page, and correct the contents of the Source tab. If you're using Maven or another tool to compile your sources instead, fix that configuration directly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download