Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Environtment Variable issue
Environtment Variable issue [message #448434] Mon, 24 April 2006 14:53 Go to next message
Eclipse UserFriend
Hello,

my native code searchs for a environtment variable using the common
getenv("variable") function. This variable must contain the path to the
java class. I'm not used to work with this, so I put the whole path ( in
unix /home/victor/workspace/plugin_name/bin/plugin/name/class ) but I get
the exception java.lang.NoClassDefFoundError. May I omit some part of the
path? I supose that getenv searches for compiled classes so I added the
/bin dir of the plugin instead the /src , I'm wrong?

I have tried with lots of diferent paths and no one worked.
I know it's a little hard question but if anyone that worked with
something similar could help me would be nice.

Thanks
Re: Environtment Variable issue [message #448516 is a reply to message #448434] Tue, 25 April 2006 12:50 Go to previous messageGo to next message
Eclipse UserFriend
Victor Llorens wrote:
> Hello,
>
> my native code searchs for a environtment variable using the common
> getenv("variable") function. This variable must contain the path to the
> java class. I'm not used to work with this, so I put the whole path ( in
> unix /home/victor/workspace/plugin_name/bin/plugin/name/class ) but I
> get the exception java.lang.NoClassDefFoundError. May I omit some part
> of the path? I supose that getenv searches for compiled classes so I
> added the /bin dir of the plugin instead the /src , I'm wrong?
>
> I have tried with lots of diferent paths and no one worked.
> I know it's a little hard question but if anyone that worked with
> something similar could help me would be nice.

What are you trying to do? You seem to have native code, an environment
variable, and java, all working with a plugin (which has it's own
complex classloading rules).

Which "part" is supposed to be doing what?

Later,
PW
Re: Environtment Variable issue [message #448583 is a reply to message #448516] Thu, 27 April 2006 08:01 Go to previous messageGo to next message
Eclipse UserFriend
Hello Paul...

We are a 3 people team developing a GUI for R with eclipse rcp. R is a
stadistical aplication. After all we are not doing the whole comunication
between R and RCP, we use a engine, JRI, produced by the people of
www.rosuda.org (They made that but with Java AWT). Since this package is
GPL we can rehuse it :p

The idea is we don't have to touch their engine, our rcp has to be
independent of the model ( JRI ) so I can't touch their code...

The comunication is made by JNI, since R only understand C.

We toke their java side package and incrusted it with eclipse as a
pluguin, yo know, new plugin and link to local system...we use callbacks
to comunicate with R , for the graphical side ( what I'm in ) there is
another package: JavaGD, taken from rosuda too...

ok i explained a litle abaout all. now I'm crashed at the following point
and it's hard to solve the problem because when you use a code that is not
yours...:

when I changed JavaGD from the original path and put it into a new plugin,
the grafical side can't start because the C code searchs for:
findclass(env, "org/rosuda/javaGD/JavaGD") path to find JavaGD constructor
method (they create a JVM at C to comunicate with Javaside), and Console
outputs:

"Error at thread-1": class /org/rosuda/javaGD/JavaGD could not be found.

There are two environtment variables in the C code: CLASSPATH and
JAVAGD_CLASS_NAME.

CLASSPATH is the classpath option of the virtual machine JavaVMInitArgs
JAVAGD_CLASS_NAME is the main device class name to find, if no defined it
searchs for /org/rosuda/javaGD/JavaGD (explained before)

Well i'm finishing, the problem may be at the CLASSPATH I think. but I set
de variable at the eclipse run configuration and it don't find the class
even if I set the CLASSPATH to /home/victor and I put the class
there...It's a paths issue I think.

Have you read all this Paul? xDD
Anyone can help me?

Everyone that reads that is a great man/woman!
Thanks!!!
Re: Environtment Variable issue [message #448589 is a reply to message #448583] Thu, 27 April 2006 08:38 Go to previous messageGo to next message
Eclipse UserFriend
Victor Llorens wrote:
>
> when I changed JavaGD from the original path and put it into a new
> plugin, the grafical side can't start because the C code searchs for:
> findclass(env, "org/rosuda/javaGD/JavaGD") path to find JavaGD
> constructor method (they create a JVM at C to comunicate with Javaside),
> and Console outputs:

OK, their JNI code is talking to the JVM instance to find a class. How
was their JNI code accessed?

If you start up a plugin, and the plugin makes a JNI call, and the JNI
code uses findClass(*), the JNI call has full access to the plugin
classpath. That means it honours the OSGi bundle classpath rules.

If a C thread makes a call into a JVM that it accessed somehow or
created itself, it doesn't have access to the plugin classpath, only the
main system classpath (which in an eclipse app is almost always just
startup.jar).


If you have the first scenario, then is the JavaGD class in the same
plugin as the JNI libs and their java classes?

Later,
PW
Re: Environtment Variable issue [message #448768 is a reply to message #448589] Mon, 01 May 2006 15:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi Paul,

I think it's the second one because the plugin doesn't acces the C code,
it's another plugin that makes so. when that plugin sends a graphic comand
to R, it's R who makes an instance of the class ( I don't know still if
creating or attahching to a virtual machine, and then loading the class.

So you say C don't have acces to the plugin?
Re: Environtment Variable issue [message #448780 is a reply to message #448768] Tue, 02 May 2006 07:32 Go to previous messageGo to next message
Eclipse UserFriend
Victor Llorens wrote:
> Hi Paul,
>
> I think it's the second one because the plugin doesn't acces the C code,
> it's another plugin that makes so. when that plugin sends a graphic
> comand to R, it's R who makes an instance of the class ( I don't know
> still if creating or attahching to a virtual machine, and then loading
> the class.
>
> So you say C don't have acces to the plugin?
>
>

If it's the scenario where some C code created it's own JVM or was
handed a JVM from a JNI call but is working in it's own thread, then
it's much more complicated.

I think this was a thread on that topic:

http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/m sg10145.html

Later,
PW
Re: Environtment Variable issue [message #448840 is a reply to message #448780] Thu, 04 May 2006 14:24 Go to previous messageGo to next message
Eclipse UserFriend
I have read all the thread and it seems that it was about a standalone
aplication that didn't work when converting the aplication to a RCP
aplication.

This is not my case, I have a standalone aplication inside my RCP working
perfectly. The standalone aplication is a Java aplication so it has it's
clases inside packages ( named like org.rosuda.javaGD ). It's when I take
one of this packages and extract it from it's origanal plugin in order to
create a new plugin with this package.Then the classloader doesn't find
the class.

This is how they use FindClass:
...
char *customClass=getenv("JAVAGD_CLASS_NAME");

if (customClass) c=(*env)->FindClass(env, customClass);
if (!c) c=(*env)->FindClass(env, "org/rosuda/javaGD/JavaGD");
if (!c) c=(*env)->FindClass(env, "JavaGD");
if (!c) { gdWarning("initJavaGD: can't find JavaGD class"); return
-2;
};
mid=(*env)->GetMethodID(env, c, "<init>", "()V");
...
Re: Environtment Variable issue [message #448893 is a reply to message #448840] Sat, 06 May 2006 11:09 Go to previous messageGo to next message
Eclipse UserFriend
Victor Llorens wrote:
> I have read all the thread and it seems that it was about a standalone
> aplication that didn't work when converting the aplication to a RCP
> aplication.
>
> This is not my case, I have a standalone aplication inside my RCP
> working perfectly. The standalone aplication is a Java aplication so it
> has it's clases inside packages ( named like org.rosuda.javaGD ). It's
> when I take one of this packages and extract it from it's origanal
> plugin in order to create a new plugin with this package.Then the
> classloader doesn't find the class.

So how did you link the new plugin with the original plugin?

newPlugin has org/rosuda/javaGD/JavaGD
original plugin requires newPlugin?

> This is how they use FindClass:
> ..
> char *customClass=getenv("JAVAGD_CLASS_NAME");
>
> if (customClass) c=(*env)->FindClass(env, customClass);
> if (!c) c=(*env)->FindClass(env, "org/rosuda/javaGD/JavaGD");
> if (!c) c=(*env)->FindClass(env, "JavaGD");
> if (!c) { gdWarning("initJavaGD: can't find JavaGD class");
> return -2; }; mid=(*env)->GetMethodID(env, c, "<init>",
> "()V");

Where did they get env from ... that matters.

Later,
PW
Re: Environtment Variable issue [message #448900 is a reply to message #448893] Sat, 06 May 2006 22:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I could have said this before but their aplication is a set of plugins
(not eclipse plugins). So JavaGD is independent and it doesn't need
anything of the remainig aplication. The aplication is independent of
JavaGD too (if not installed R uses X11 Device as default).

they get env attaching to the current JVM ( There's two created (eclipse
one, RCP one) but I supose it always attaches with the RCP one since it
worked well before transporting the package to a new plugin). I attach
the code . JavaVM *jvm variable is set before to 0; the first time I
invoke de class in my RCP it's value is 0, after that, in future invokings
is, well, 1 ...:

static JNIEnv *getJNIEnv() {
JNIEnv *env;
jsize l;
jint res;

if (!jvm) {
res= JNI_GetCreatedJavaVMs(&jvm, 1, &l);
if (res!=0) {
fprintf(stderr, "JNI_GetCreatedJavaVMs failed! (%d)\n",res);
return 0;
}
if (l<1) {
fprintf(stderr, "JNI_GetCreatedJavaVMs said there's no JVM
running!\n"); return 0;
}
}
res = (*jvm)->AttachCurrentThread(jvm, &env, 0);
if (res!=0) {
fprintf(stderr, "AttachCurrentThread failed! (%d)\n",res); return
0;
}
return env;
}

I have had fun printing to eclipse console all steps of the C code (with
fprintf(stderr,"",var) ) and definetly it fails at the first FindClass,
and at all the rest because c variable is always 0.
Re: Environtment Variable issue [message #448901 is a reply to message #448900] Sat, 06 May 2006 22:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I missed that: I imagine the javaVM that C thread is attached to has it's
visibility only at the plugin where it was created. I thing it's something
like this. This is the only reason that explains why eclipse found the
class at first,and why not when I changed it to another plugin.

An awesome thread, thanks a lot.

Victor,
17M FCB=winner
Re: Environtment Variable issue [message #448984 is a reply to message #448583] Mon, 08 May 2006 10:19 Go to previous messageGo to next message
Eclipse UserFriend
Maybe a Makefile included in the package "org.rosuda.javaGD" has an
important role at this situation... I include the code for all can see,
but I will continue googling:

SRC:=$(wildcard *.java)
OBJ:=$(SRC:%.java=org/rosuda/javaGD/%.class)
JAR=javaGD.jar

TARGETS=$(JAR)

JAVAC=javac $(JFLAGS)

all: $(JAR)

org/rosuda/javaGD/JavaGD.class: JavaGD.java
org/rosuda/javaGD/GDCanvas.class
$(JAVAC) -d . $<

org/rosuda/javaGD/XGDserver.class: XGDserver.java
org/rosuda/javaGD/GDCanvas.class
$(JAVAC) -d . $<

org/rosuda/javaGD/%.class: %.java
$(JAVAC) -d . $^

$(JAR): $(OBJ)
jar fc $@ org

clean:
rm -rf org *~ $(TARGETS)

PHONY: all clean


Bye
Re: Environtment Variable issue [message #449619 is a reply to message #448583] Tue, 16 May 2006 18:39 Go to previous message
Eclipse UserFriend
Hello,

finally I have solved the problem. I have done it this way:

- I named the new plugin identically as the package name.
- I didin't delete any files from the new package created. There is one
called *Plugin.java that seems to be important for this to work. In the
other plugins I deleted it and they work fine...
- I pasted my original classes inside the new package.
- I exported the package from the new plugin.
- I added the new plugin as a dependency of org.rosuda.JRI plugin.

But this is the problem: JavaGD needs JRI too. If I add javaGD as a
dependency for JRI in order to JNI recognize JavaGD path, eclipse there's
a cycle in the arquitechture...

Any ideas?
Thanks
Previous Topic:Problems creating an editor. Help please?
Next Topic:How transfer my plug-in project to RCP project?
Goto Forum:
  


Current Time: Sun Aug 31 04:23:05 EDT 2025

Powered by FUDForum. Page generated in 0.04207 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top