J Ellis
J Ellis

Reputation: 678

How do I fix a "declared package does not match the expected package" error on Eclipse?

I've feel like I have gone through the proper steps to fix this error, and I've looked at other questions about this in SO and other places, but for some reason I'm still having an issue.

I am trying to set up a project using the Apache JMeter source code.

As an example, the file BeanShellAssertion.java is in

~/workspace/apache-jmeter-2.9/src/components/org/apache/jmeter/assertions.

My source folder is src/components. The package declaration in BeanShellAssertion.java is

package org.apache.jmeter.assertions;

Looking at it, it seems like everything is set up the way it is supposed to be. However, the package declaration is causing an error:

The declared package "org.apache.jmeter.assertions" does not match the
expected package "components.org.apache.jmeter.assertions"

Image is below. What exactly am I doing wrong here?

enter image description here

enter image description here

Upvotes: 9

Views: 32910

Answers (4)

Jebeh Kawah
Jebeh Kawah

Reputation: 21

In my situation, what was missing was the package statement, so I added (for example):

package CentralBCTestJK; // as the first line in my .java file

Upvotes: 0

Joe.Hurke
Joe.Hurke

Reputation: 31

Removing the src folder fixes this error, but it leads to other problems. For example refactoring of this code does not work anymore, because it depends on the build path. I recommend: Right-click the project -> Select Maven -> Update Project... -> (Set CheckBox:) Force Update... This also fixed this error for me and e.g. refactoring of the code in the src directories can be done afterwards.

Upvotes: 0

Kumar S
Kumar S

Reputation: 441

Once I imported an existing maven project, I right clicked on the src folder and removed it from the build path. This fixed the error.

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240956

put your src/components/ to source path

right click > properties > java build path > source > add folder > select src/components

Upvotes: 10

Related Questions