Dynamic compilation fails with "cannot be resolved to a type"

L

Lionel

Hi all,

I'm using EclipseCompiler (open to suggestions of alternatives, as long
as they are smaller as this is only 1.6MB) to compile source code that I
write at runtime I get the following error:

1. ERROR in \UserDefinedGentamicin.java (at line 2)
public class UserDefinedGentamicin extends
tciworks.drugmodel.CommonDerivnFunction {

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tciworks.drugmodel.CommonDerivnFunction cannot be resolved to a type


The background.

tciworks.drugmodel.CommonDerivnFunction is an Abstract class that is
compiled and included as a class file in the application jar file.

tciworks.drugmodel.UserDefinedGentamicin.java is created at runtime and
it is while I am attempting to compile UserDefinedGentamicin.java that
the above error occurs. The error occurs when I run the application, but
when I test it with JUnit/Ant, it is fine!

Clearly the CommonDerivnFunction class can't be found, I would have
thought this would automatically be in the classpath?

I also wrote sample program based on my code and I got the same error
once or twice, but I can't reproduce it now so unless anyone thinks it
will be of use (it's fairly large still) then there isn't much point
posting it.

Any ideas? How can I debug this?

Thanks

Lionel.
 
M

Mark Space

Lionel said:
Clearly the CommonDerivnFunction class can't be found, I would have
thought this would automatically be in the classpath?

Nope. I don't use Eclipse, but when I looked at it I remember I had to
drag .jar files into a library folder in the project if I wanted to use
anything besides the standard classes. It might be under Properties too
if you right click on the project folder in Eclipse. Jar files do NOT
magically appear on your classpath just because you've copied them onto
your hard disc.

Also, make absolutely certain you are spelling the class name correctly.
 
L

Lionel

Mark said:
Nope. I don't use Eclipse,


Neither do I, I'm just using the jar that contains the eclipse compiler.
In fact I've run this app in Netbeans, and outside of Netbeans as I have
my own ant script to do all compilation and packaging. The class not
found is also not an Eclipse class.

Also, make absolutely certain you are spelling the class name correctly.

Will check again, although the fact that it works when running JUnit
tests suggests this is OK.

Thanks

Lionel.
 
L

Lionel

Lionel said:
Hi all,

I'm using EclipseCompiler (open to suggestions of alternatives, as long
as they are smaller as this is only 1.6MB) to compile source code that I
write at runtime I get the following error:

1. ERROR in \UserDefinedGentamicin.java (at line 2)
public class UserDefinedGentamicin extends
tciworks.drugmodel.CommonDerivnFunction {

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tciworks.drugmodel.CommonDerivnFunction cannot be resolved to a type

It appears I left out some critical information. My application is a JWS
app and it appears that classes are loaded differently in JWS.

If I do the following from a non-JWS app anywhere in the code:

class SomeClass extends ClassLoader {

public SomeClass() {
}

@Override
public Package[] getPackages() {
return super.getPackages();
}
}
SomeClass someClass = new SomeClass();
for (final Package pkg : someClass.getPackages()) {
System.err.println("->" + pkg.getName());
}

I will see my application packages in amongst all the java ones. But if
I do it in the JWS app I only see the java packages.

So, anyone know how I solve this problem? How do I extend a class that I
have defined and compile it dynamically?

Thanks

Lionel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top