Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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

like image 662
J Ellis Avatar asked Jul 15 '13 20:07

J Ellis


People also ask

How do I fix a package error in Eclipse?

Go to src folder of the project and copy all the code from it to some temporary location and build the project. And now copy the actual code from temporary location to project src. And run the build again. Problem will be resolved.

Is package declaration mandatory in Java?

It's mandatory that class files reside on the same package or directory as declared in their source file using package keyword, failure to do will result in java.


2 Answers

put your src/components/ to source path

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

like image 198
jmj Avatar answered Oct 25 '22 08:10

jmj


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.

like image 25
Kumar S Avatar answered Oct 25 '22 08:10

Kumar S