Jason S
Jason S

Reputation: 189886

Access restriction on class due to restriction on required library

I get this error message in Eclipse:

Access restriction: The type DirectoryWalker is not accessible
due to restriction on required library 
/Library/Java/Extensions/commons-io-1.4.jar

what does this mean? There's this other SO question on the same topic but it doesn't seem to apply in this case. I'm not creating a new java class, I'm trying to use one.

Upvotes: 19

Views: 72186

Answers (9)

Joost
Joost

Reputation: 546

For those looking why Eclipse can build the project, but Maven can't, check if you have JUnit as a Library, or as a plugin dependency. If it is added as a library, Maven will not be able to pick it up and throw many access restriction (type xyz is not API).

Upvotes: 0

CMA
CMA

Reputation: 2818

In my case, I was able to solve this by unticking the folder attribute 'Read-only' in the Properties of the project folder.

Then, I re-configured Build path of the project, then Clean.

It had solved the error.

Upvotes: 0

Hasan Sawan
Hasan Sawan

Reputation: 421

Project build path settings -> Libraries tab -> select JRE System Library -> Edit button -> change from Execution Environment radio tab which says J2SE 1.x (jdk1.6.0_21) to Workspace default JRE (jdk1.6.0_21) [Collected]

This is the best solution for sure!

Upvotes: 3

drverboten
drverboten

Reputation: 335

I had the same error the way I fixed was setting the default workspace JRE to the same as the project, I had JRE6 for the workspace and JRE7 for the project setting both to JRE7 fixed the problem

Upvotes: 1

Michael Eric Oberlin
Michael Eric Oberlin

Reputation: 131

This is my least-favorite error, I've run into it a few times, and the "restriction on required library" is just dull enough to leave you scratching your head. However, it's easy to fix.

The quickest way (I'm using Helios) is to go to Window->Preferences->Java->Compiler->Errors/Warnings, find and open the "Deprecated and Restricted API" bullet, and set Forbidden and Discouraged Reference to something other than Error.

"Warning" is usually best, as something out there in Java land is triggering this and you probably want a footnote on it. @SuppressWarnings and its cousins, 98% of the time, have the same effect on a programmer's personal and social logic as, say, an ether binge might. But that's just my humble analysis.

Best of luck!

Upvotes: 13

David Carboni
David Carboni

Reputation: 2186

If you are using m2eclipse, I find "Update Project Configuration" fixes it.

Right-click the project, select Maven > Update Project Configuration and give it a few seconds.

Upvotes: 0

Maheen
Maheen

Reputation: 751

go to java build path and under Library tab, remove JRE System Library. Then again Add Library --> JRE System Library

Worked for me

Upvotes: 75

Ben
Ben

Reputation: 7597

For what it's worth, I had this error recently too (different library).

My IDE (MyEclipse) references a certain library as part of the overall project classpath, but I also had a copy of the relevant JAR in my machine's Java extensions folder.

The resulting clash gave the (unhelpful) error that you've experienced. So for anyone else hitting this error, you might want to consider your classpaths too.

Upvotes: 4

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147164

At a guess another library you are using also requires Apache Commons I/O, but a different version. Having a piece of code (transitively) have access to two versions of the same packages is a little tricky. You can probably arrange it so your code and the other library use the same version. It's all much easier with CLASSPATH! :)

Upvotes: 6

Related Questions