Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

JavaCompiler example -- trouble with finding class definitions

Thread view: 
Robert Dodier - 23 Nov 2006 00:02 GMT
Hello,

I am working with two examples of using the JavaCompiler class in JDK
6:
http://groups.google.com/group/comp.lang.java.programmer/msg/0243d70fbce78e52?dm
ode=source&hl=en

http://groups.google.com/group/comp.lang.java.programmer/msg/3265954fdaac103e?dm
ode=source&hl=en


I find that, after making just a few minor modifications
(JavaCompilerTool --> JavaCompiler, getResult --> call,
getStandardFileManager(diagnostics) -->
getStandardFileManager(diagnostics, null, null))
the examples run as expected. (The JavaCompiler stuff has changed
since the examples were written.) Thanks very much to the authors.

I can also modify the source code strings so that functions
such as Math.sin or Math.exp are called, and these work as expected.

However, I find that when I try to call some method which I wrote
(e.g. with FOOBAR defined as public class FOOBAR { public FOOBAR () {}
public double FOO (double x) { return x*x; }}, I try FOOBAR f = new
FOOBAR ();
f.FOO(2.0); in the source code string) then the compilation fails with
"cannot find symbol
symbol  : class FOOBAR"
which is disappointing.

I tried specifying the classpath in different ways -- e.g. -cp . or
-Xbootclasspath/a:. or -cp FOOBAR.jar (after putting FOOBAR.class into
a jar file) or export CLASSPATH=. but none of those help java find
FOOBAR.

If I cut-n-paste the source code into a file, and compile it on the
command
line, then it works OK.

I wonder if anyone has some words of wisdom here.
Thanks in advance for your help.

Robert Dodier
hiwa - 23 Nov 2006 03:14 GMT
> Hello,
>
[quoted text clipped - 35 lines]
>
> Robert Dodier
Post a small demo code that is generally compilable, runnable and could
reproduce your problem. See:
http://homepage1.nifty.com/algafield/sscce.html and
http://www.yoda.arachsys.com/java/newsgroups.html
Robert Dodier - 27 Nov 2006 19:24 GMT
Hello,

I've resolved the problem with the examples which I mentioned before.
It turns out the problem is very simple: The examples generate
code which is declared to be in package just.generated .
So the class FOOBAR needs to also be in package just.generated
(or, more generally, any referenced class needs to be visible
to classes in the package just.generated).

When I add "package just.generated;" to FOOBAR.java and
recompile it (using the command line javac) then the examples
work as expected when the generated code references
just.generated.FOOBAR .

Thanks again to the authors of the examples, which are very helpful.
Hope this info is useful to someone.

Robert Dodier


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.