Eclipse: Use 'Type Access Rules' to restrict classes to java.[lang|util]

762 views
Skip to first unread message

robertito

unread,
May 20, 2006, 5:04:17 AM5/20/06
to Google Web Toolkit
If you're placing GWT client-side code in it's own Eclipse project, you
can use 'Type Access Rules' to get warnings if you step outside the
supported JRE Emulation Library
(http://code.google.com/webtoolkit/documentation/jre.html).

To do this, go to the Eclipse project settings and select 'Java Build
Path', 'Libraries'. Open the entry for your JDK/JRE library, and select
'Access Rules', then 'Edit'. You need to add 3 rules, in this order:

Accessible : java/lang/*
Accessible : java/util/*
Forbidden : **

This will stop Eclipse from offering you JRE classes outside
java.[lang|util], and will also give you an error if you manually type
one in. Obviously, you'd get an error anyway if you attempted to run it
in GWT hosted mode, but more immediate feedback is always a good thing!

In addition you can set the project-specific Java Compiler source
compatability level to Java v1.4 - so you don't accidentally start
using generics or other unavailable language features.

Roberto

musachy

unread,
May 20, 2006, 10:30:55 AM5/20/06
to Google Web Toolkit
but for that GWT would need to be an eclipse plugin, right?

robertito

unread,
May 20, 2006, 5:13:34 PM5/20/06
to Google Web Toolkit
Nope - while there is room for further integration with Eclipse, making
a fully fleged plugin - there's certainly no reason why you can't write
and even run GWT code within Eclipse. See:

http://code.google.com/webtoolkit/gettingstarted.html#NewEclipse

-there are even scripts (projectCreator & applicationCreator) to create
blank GWT Eclipse projects.

I''m using a slightly different file layout to that recommended in the
standard GWT package layout
(http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.Fundamentals.ProjectStructure.html)
- basically because I want to be able to code GWT client-side within
as restricted environment as possible, yet also compile my server side
code in a full-fat mustang-with-a-banana environment. Eclipse only lets
you set one compiler complience level and build path per project, so
this requires two projects, eg. myapp-server & myapp-gwt. The file
layout ends up looking like this:

myapp-server/src/com/example/cal/server/spelling/SpellingServiceImpl.java

myapp-gwt/src/com/example/cal/client/spelling/SpellingService.java
myapp-gwt/src/com/example/cal/public/Calendar.html

It's working pretty well for me so far.

cheers,
Roberto

Reply all
Reply to author
Forward
0 new messages