Home » Language IDEs » Java Development Tools (JDT) » Adding tools.jar to the classpath
Adding tools.jar to the classpath [message #257662] |
Thu, 04 December 2008 05:11  |
Eclipse User |
|
|
|
Originally posted by: clement.mathieu.activeeon.com
Hi,
We just added a static code checker based on annotations to our
project. Since the checkers rely on the mirror API, the tools.jar file
is now required by our project to build fine.
How can I automatically add the JDK/lib/tools.jar to the project
classpath ?
I tried various tricks in the .classpath
and .project/org.eclipse.jdt.core.prefs file but I failed to have my
project working out of box. I'm trying to avoid the "Add a JDK variable
to your project/workspace" step since it is painful for the developers.
Any idea ?
Thanks.
|
|
| | |
Re: Adding tools.jar to the classpath [message #257686 is a reply to message #257662] |
Thu, 04 December 2008 18:27   |
Eclipse User |
|
|
|
"Clement Mathieu" <clement.mathieu@activeeon.com> wrote in message
news:20081204111100.00dde776@britany.activeeon.com...
> Hi,
>
> We just added a static code checker based on annotations to our
> project. Since the checkers rely on the mirror API, the tools.jar file
> is now required by our project to build fine.
>
> How can I automatically add the JDK/lib/tools.jar to the project
> classpath ?
>
> I tried various tricks in the .classpath
> and .project/org.eclipse.jdt.core.prefs file but I failed to have my
> project working out of box. I'm trying to avoid the "Add a JDK variable
> to your project/workspace" step since it is painful for the developers.
AFAIK there is unfortunately no good, environment-independent, way of adding
external libraries to the classpath.
It is not quite clear from your message whether you're writing an annotation
processor per se, but if not, you might consider taking that approach.
Also, you might consider writing to the Java 6 version of that API,
javax.annotation.processing, which is standardized and is part of the normal
Java SE API, no extra jars required.
By the way, if you develop your code checker as an Eclipse plug-in,
dependent on org.eclipse.jdt.apt.core, you will get the Mirror API resolved
automagically. The resulting plug-in can then be exported as a jar file for
use at the command line. Details on writing such "dual-mode" annotation
processors are in an EclipseCon 2007 tutorial, the content of which is
linked from the Eclipse JDT APT web page,
http://www.eclipse.org/jdt/apt/index.html. I apologize for the awful
condition of the web page.
But regardless, since Eclipse implements the com.sun.mirror.apt API, Sun
graciously permitted us to include it in org.eclipse.jdt.apt.core, and it is
thus available to you for reuse if you would like - you could include it in
your own project. The terms of the Sun license are in a text file in the
apt.core project (also contained in the plug-in itself), and I've copied
them below. As it says, "Redistribution and use in source and binary
forms... are permitted" with some conditions.
====================
Copyright (c) 2004, Sun Microsystems, Inc.All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the Sun Microsystems, Inc. nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
Re: Adding tools.jar to the classpath [message #257694 is a reply to message #257686] |
Fri, 05 December 2008 04:47  |
Eclipse User |
|
|
|
Originally posted by: clement.mathieu.activeeon.com
On Thu, 4 Dec 2008 15:27:59 -0800
"Walter Harley" <eclipse@cafewalter.com> wrote:
> AFAIK there is unfortunately no good, environment-independent, way of
> adding external libraries to the classpath.
I came to the same conclusion.
> It is not quite clear from your message whether you're writing an
> annotation processor per se, but if not, you might consider taking
> that approach. Also, you might consider writing to the Java 6 version
> of that API, javax.annotation.processing, which is standardized and
> is part of the normal Java SE API, no extra jars required.
We develop a framework for distributed and parallel computing.
It imposes a few, lightweight, restrictions on user code like
"this class cannot be final" or "you must use a getter/setter
instead of using the field". User can now tag their objects with
a few annotations and our checker will warn them at compile time
when a construct is not compatible with our framework.
Since we want to support Java 5, we use apt and the mirror API when
Java 5 is used and javax.annotation/compiler tree API if Java 6. We
decided to implement two versions of the checkers since Java 6 is much
more powerful but we have to support Java 5.
> By the way, if you develop your code checker as an Eclipse plug-in,
> dependent on org.eclipse.jdt.apt.core, you will get the Mirror API
> resolved automagically. The resulting plug-in can then be exported
> as a jar file for use at the command line. Details on writing such
> "dual-mode" annotation processors are in an EclipseCon 2007 tutorial,
> the content of which is linked from the Eclipse JDT APT web page,
> http://www.eclipse.org/jdt/apt/index.html. I apologize for the awful
> condition of the web page.
Thanks for the pointer !
|
|
|
Goto Forum:
Current Time: Thu Apr 24 23:39:45 EDT 2025
Powered by FUDForum. Page generated in 0.03402 seconds
|