Home » Eclipse Projects » Eclipse Platform » Problem invoking static methods.
Problem invoking static methods. [message #309787] |
Wed, 08 November 2006 17:49  |
Eclipse User |
|
|
|
Originally posted by: jpk4077.hotmail.com
This is a multi-part message in MIME format.
------=_NextPart_000_0276_01C7035E.3411CF20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
I am not sure why but I am not able to invoke a static function from =
within a popupmenu plugin. common is another package in the same plugin =
project. I am attaching the code where I am invoking a static function =
of another class Utils. The output only shows "BEFORE".
On debug, earlier eclipse showed me a class not found error, now it does =
not show me anything. I have done a project clean and a full compile and =
the class files are present in the right directory.
Tx Praveen.
---------------------------------
package common;
public class Utils {
public static void writeToFile(String str, String fileLocation,
String fileName) {
System.out.println("INSIDE..." + str + " :: " + fileName);
}
}
---------------------------------
package plugin.actions;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
public class ConvertAction implements IObjectActionDelegate {
public void run(IAction action) {
if (!m_Selection.isEmpty()) {
IStructuredSelection sel =3D (IStructuredSelection) =
m_Selection;
Object obj =3D sel.getFirstElement();
if (obj instanceof IFile) {
IFile file =3D (IFile) obj;
IContainer cont =3D file.getParent();
String fileName =3D file.getName();
String location =3D file.getLocation().toOSString();
String fileDir =3D location.substring(0, =
location.length()
- fileName.length() - 1);
String str =3D "TEXT";
System.out.println("BEFORE");
Utils.writeToFile(str, fileDir, "MyFile.txt");
System.out.println("AFTER");
}
}
}
}
}
---------------------------------
------=_NextPart_000_0276_01C7035E.3411CF20
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1476" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>I am not sure why but =
I am not able=20
to invoke a static function from within a popupmenu plugin. common is =
another=20
package in the same plugin project. I am attaching the code where I am =
invoking=20
a static function of another class Utils. The output only shows=20
"BEFORE".</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>On debug, earlier =
eclipse showed me=20
a class not found error, now it does not show me anything. I have done a =
project=20
clean and a full compile and the class files are present in the right=20
directory.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Tx =
Praveen.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>---------------------------------</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>package =
common;</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>public class Utils=20
{<BR> public static void writeToFile(String str, =
String=20
fileLocation,<BR> &n=
bsp; =20
String fileName) {<BR> =20
System.out.println("INSIDE..." + str + " :: " + =
fileName);<BR> =20
}<BR>}</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>---------------------------------</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>package =
plugin.actions;<BR>import=20
org.eclipse.core.resources.IContainer;<BR>import=20
org.eclipse.core.resources.IFile;<BR>import=20
org.eclipse.core.resources.IProject;<BR>import=20
org.eclipse.core.resources.IResource;<BR>import=20
org.eclipse.core.resources.IncrementalProjectBuilder;<BR>import=20
org.eclipse.core.runtime.CoreException;<BR>import=20
org.eclipse.jface.action.IAction;<BR>import=20
org.eclipse.jface.viewers.ISelection;<BR>import=20
org.eclipse.jface.viewers.IStructuredSelection;<BR>import=20
org.eclipse.ui.IActionDelegate;<BR>import=20
org.eclipse.ui.IObjectActionDelegate;<BR>import=20
org.eclipse.ui.IWorkbenchPart;</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>public class =
ConvertAction=20
implements IObjectActionDelegate {<BR> public void =
run(IAction=20
action) {<BR> if=20
(!m_Selection.isEmpty())=20
{<BR> =20
IStructuredSelection sel =3D (IStructuredSelection)=20
m_Selection;<BR> &nb=
sp; =20
Object obj =3D=20
sel.getFirstElement();<BR>  =
; =20
if (obj instanceof IFile)=20
{<BR> &n=
bsp; =20
IFile file =3D (IFile)=20
obj;<BR>  =
; =20
IContainer cont =3D=20
file.getParent();<BR> &nbs=
p; &nbs p;=20
String fileName =3D=20
file.getName();<BR> =
=20
String location =3D=20
file.getLocation().toOSString();<BR> &=
nbsp; & nbsp; =20
String fileDir =3D location.substring(0,=20
location.length()<BR> &nbs=
p; &nbs p; &nbs p=
; =20
- fileName.length() -=20
1);<BR> =
=20
String str =3D=20
"TEXT";<BR>System.out.println("BEFORE");<BR>  =
;   ;   ;=
=20
Utils.writeToFile(str, fileDir,=20
"MyFile.txt");<BR>System.out.println("AFTER");<BR>  =
;   ; =20
}<BR> }<BR> =20
}<BR> }<BR>}</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>---------------------------------</FONT></DIV></BODY ></HTML>
------=_NextPart_000_0276_01C7035E.3411CF20--
|
|
|
Re: Problem invoking static methods. [message #309788 is a reply to message #309787] |
Wed, 08 November 2006 17:55   |
Eclipse User |
|
|
|
Originally posted by: jpk4077.hotmail.com
This is a multi-part message in MIME format.
------=_NextPart_000_0285_01C7035F.1FD7EED0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I am able to invoke the static method from a regular class as follows. =
So the eclipse JDK has the class path etc. setup. I suspect its some =
tweak I need to make in the plugin execution environment.
Thanks Praveen.
import common.Utils;
public class asd {
public static void main(String[] args) {
Utils.writeToFile("A", "C:\\ad", "QWE.txt");
}
}
"Praveen" <jpk4077@hotmail.com> wrote in message =
news:eitmt9$lvs$1@utils.eclipse.org...
Hi,
I am not sure why but I am not able to invoke a static function from =
within a popupmenu plugin. common is another package in the same plugin =
project. I am attaching the code where I am invoking a static function =
of another class Utils. The output only shows "BEFORE".
On debug, earlier eclipse showed me a class not found error, now it =
does not show me anything. I have done a project clean and a full =
compile and the class files are present in the right directory.
Tx Praveen.
---------------------------------
package common;
public class Utils {
public static void writeToFile(String str, String fileLocation,
String fileName) {
System.out.println("INSIDE..." + str + " :: " + fileName);
}
}
---------------------------------
package plugin.actions;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
public class ConvertAction implements IObjectActionDelegate {
public void run(IAction action) {
if (!m_Selection.isEmpty()) {
IStructuredSelection sel =3D (IStructuredSelection) =
m_Selection;
Object obj =3D sel.getFirstElement();
if (obj instanceof IFile) {
IFile file =3D (IFile) obj;
IContainer cont =3D file.getParent();
String fileName =3D file.getName();
String location =3D file.getLocation().toOSString();
String fileDir =3D location.substring(0, =
location.length()
- fileName.length() - 1);
String str =3D "TEXT";
System.out.println("BEFORE");
Utils.writeToFile(str, fileDir, "MyFile.txt");
System.out.println("AFTER");
}
}
}
}
}
---------------------------------
------=_NextPart_000_0285_01C7035F.1FD7EED0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1476" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>I am able to invoke the static method from a regular class as =
follows. So=20
the eclipse JDK has the class path etc. setup. I suspect its some tweak =
I need=20
to make in the plugin execution environment.</DIV>
<DIV> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Thanks =
Praveen.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>import =
common.Utils;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>public class asd =
{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2> =
public static=20
void main(String[] args) {<BR> =
Utils.writeToFile("A", "C:\\ad", "QWE.txt");<BR> =20
}<BR>}<BR></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Praveen" <<A=20
href=3D"mailto:jpk4077@hotmail.com">jpk4077@hotmail.com</A>> wrote =
in message=20
<A=20
=
href=3D"news:eitmt9$lvs$1@utils.eclipse.org">news:eitmt9$lvs$1@utils.ecli=
pse.org</A>...</DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>I am not sure why =
but I am not=20
able to invoke a static function from within a popupmenu plugin. =
common is=20
another package in the same plugin project. I am attaching the code =
where I am=20
invoking a static function of another class Utils. The output only =
shows=20
"BEFORE".</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>On debug, earlier =
eclipse showed=20
me a class not found error, now it does not show me anything. I have =
done a=20
project clean and a full compile and the class files are present in =
the right=20
directory.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Tx =
Praveen.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>---------------------------------</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>package =
common;</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>public class Utils=20
{<BR> public static void writeToFile(String str, =
String=20
=
fileLocation,<BR> &n=
bsp; =20
String fileName) {<BR> =20
System.out.println("INSIDE..." + str + " :: " +=20
fileName);<BR> }<BR>}</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
size=3D2>---------------------------------</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>package =
plugin.actions;<BR>import=20
org.eclipse.core.resources.IContainer;<BR>import=20
org.eclipse.core.resources.IFile;<BR>import=20
org.eclipse.core.resources.IProject;<BR>import=20
org.eclipse.core.resources.IResource;<BR>import=20
org.eclipse.core.resources.IncrementalProjectBuilder;<BR>import=20
org.eclipse.core.runtime.CoreException;<BR>import=20
org.eclipse.jface.action.IAction;<BR>import=20
org.eclipse.jface.viewers.ISelection;<BR>import=20
org.eclipse.jface.viewers.IStructuredSelection;<BR>import=20
org.eclipse.ui.IActionDelegate;<BR>import=20
org.eclipse.ui.IObjectActionDelegate;<BR>import=20
org.eclipse.ui.IWorkbenchPart;</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>public class =
ConvertAction=20
implements IObjectActionDelegate {<BR> public void=20
run(IAction action) {<BR> if =
(!m_Selection.isEmpty())=20
=
{<BR> =20
IStructuredSelection sel =3D (IStructuredSelection)=20
=
m_Selection;<BR> &nb=
sp; =20
Object obj =3D=20
=
sel.getFirstElement();<BR>  =
; =20
if (obj instanceof IFile)=20
=
{<BR> &n=
bsp; =20
IFile file =3D (IFile)=20
=
obj;<BR>  =
; =20
IContainer cont =3D=20
=
file.getParent();<BR> &nbs=
p; &nbs p;=20
String fileName =3D=20
=
file.getName();<BR> =
=20
String location =3D=20
=
file.getLocation().toOSString();<BR> &=
nbsp; & nbsp; =20
String fileDir =3D location.substring(0,=20
=
location.length()<BR> &nbs=
p; &nbs p; &nbs p=
; =20
- fileName.length() -=20
=
1);<BR> =
=20
String str =3D=20
=
"TEXT";<BR>System.out.println("BEFORE");<BR>  =
;   ;   ;=
=20
Utils.writeToFile(str, fileDir,=20
=
"MyFile.txt");<BR>System.out.println("AFTER");<BR>  =
;   ; =20
}<BR> =
}<BR> =20
}<BR> }<BR>}</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080=20
=
size=3D2>---------------------------------</FONT></DIV></BLOCKQUOTE ></BOD=
Y></HTML>
------=_NextPart_000_0285_01C7035F.1FD7EED0--
|
|
|
Re: Problem invoking static methods. [message #309790 is a reply to message #309788] |
Wed, 08 November 2006 20:25   |
Eclipse User |
|
|
|
Originally posted by: wegener.cboenospam.com
Praveen wrote:
> I am able to invoke the static method from a regular class as follows.
> So the eclipse JDK has the class path etc. setup. I suspect its some
> tweak I need to make in the plugin execution environment.
>
> Thanks Praveen.
>
> import common.Utils;
>
> public class asd {
>
> public static void main(String[] args) {
> Utils.writeToFile("A", "C:\\ad", "QWE.txt");
> }
> }
>
> "Praveen" <jpk4077@hotmail.com <mailto:jpk4077@hotmail.com>> wrote
> in message news:eitmt9$lvs$1@utils.eclipse.org...
> Hi,
>
> I am not sure why but I am not able to invoke a static function from
> within a popupmenu plugin. common is another package in the same
> plugin project. I am attaching the code where I am invoking a static
> function of another class Utils. The output only shows "BEFORE".
>
> On debug, earlier eclipse showed me a class not found error, now it
> does not show me anything. I have done a project clean and a full
> compile and the class files are present in the right directory.
>
> Tx Praveen.
> ---------------------------------
> package common;
>
> public class Utils {
> public static void writeToFile(String str, String fileLocation,
> String fileName) {
> System.out.println("INSIDE..." + str + " :: " + fileName);
> }
> }
> ---------------------------------
> package plugin.actions;
> import org.eclipse.core.resources.IContainer;
> import org.eclipse.core.resources.IFile;
> import org.eclipse.core.resources.IProject;
> import org.eclipse.core.resources.IResource;
> import org.eclipse.core.resources.IncrementalProjectBuilder;
> import org.eclipse.core.runtime.CoreException;
> import org.eclipse.jface.action.IAction;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.IStructuredSelection;
> import org.eclipse.ui.IActionDelegate;
> import org.eclipse.ui.IObjectActionDelegate;
> import org.eclipse.ui.IWorkbenchPart;
>
> public class ConvertAction implements IObjectActionDelegate {
> public void run(IAction action) {
> if (!m_Selection.isEmpty()) {
> IStructuredSelection sel = (IStructuredSelection)
> m_Selection;
> Object obj = sel.getFirstElement();
> if (obj instanceof IFile) {
> IFile file = (IFile) obj;
> IContainer cont = file.getParent();
> String fileName = file.getName();
> String location = file.getLocation().toOSString();
> String fileDir = location.substring(0, location.length()
> - fileName.length() - 1);
> String str = "TEXT";
> System.out.println("BEFORE");
> Utils.writeToFile(str, fileDir, "MyFile.txt");
> System.out.println("AFTER");
> }
> }
> }
> }
> }
> ---------------------------------
I notice that your code doesn't include an import for common.Utils. Is
this just a cut and paste omission?
|
|
|
Re: Problem invoking static methods. [message #309791 is a reply to message #309790] |
Wed, 08 November 2006 22:43   |
Eclipse User |
|
|
|
Originally posted by: jpk4077.hotmail.com
This is a multi-part message in MIME format.
------=_NextPart_000_034F_01C70387.5B3F1E80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Yes, I apologize for the typo.
~Praveen.
"David Wegener" <wegener@cboenospam.com> wrote in message =
news:eiu033$csi$2@utils.eclipse.org...
Praveen wrote:
> I am able to invoke the static method from a regular class as =
follows.=20
> So the eclipse JDK has the class path etc. setup. I suspect its some =
> tweak I need to make in the plugin execution environment.
> =20
> Thanks Praveen.
> =20
> import common.Utils;
> =20
> public class asd {
> =20
> public static void main(String[] args) {
> Utils.writeToFile("A", "C:\\ad", "QWE.txt");
> }
> }
>=20
> "Praveen" <jpk4077@hotmail.com <mailto:jpk4077@hotmail.com>> =
wrote
> in message news:eitmt9$lvs$1@utils.eclipse.org...
> Hi,
> =20
> I am not sure why but I am not able to invoke a static function =
from
> within a popupmenu plugin. common is another package in the same
> plugin project. I am attaching the code where I am invoking a =
static
> function of another class Utils. The output only shows "BEFORE".
> =20
> On debug, earlier eclipse showed me a class not found error, now =
it
> does not show me anything. I have done a project clean and a =
full
> compile and the class files are present in the right directory.
> =20
> Tx Praveen.
> ---------------------------------
> package common;
> =20
> public class Utils {
> public static void writeToFile(String str, String =
fileLocation,
> String fileName) {
> System.out.println("INSIDE..." + str + " :: " + =
fileName);
> }
> }
> ---------------------------------
> package plugin.actions;
> import org.eclipse.core.resources.IContainer;
> import org.eclipse.core.resources.IFile;
> import org.eclipse.core.resources.IProject;
> import org.eclipse.core.resources.IResource;
> import org.eclipse.core.resources.IncrementalProjectBuilder;
> import org.eclipse.core.runtime.CoreException;
> import org.eclipse.jface.action.IAction;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.IStructuredSelection;
> import org.eclipse.ui.IActionDelegate;
> import org.eclipse.ui.IObjectActionDelegate;
> import org.eclipse.ui.IWorkbenchPart;
> =20
> public class ConvertAction implements IObjectActionDelegate {
> public void run(IAction action) {
> if (!m_Selection.isEmpty()) {
> IStructuredSelection sel =3D (IStructuredSelection)
> m_Selection;
> Object obj =3D sel.getFirstElement();
> if (obj instanceof IFile) {
> IFile file =3D (IFile) obj;
> IContainer cont =3D file.getParent();
> String fileName =3D file.getName();
> String location =3D =
file.getLocation().toOSString();
> String fileDir =3D location.substring(0, =
location.length()
> - fileName.length() - 1);
> String str =3D "TEXT";
> System.out.println("BEFORE");
> Utils.writeToFile(str, fileDir, =
"MyFile.txt");
> System.out.println("AFTER");
> }
> }
> }
> }
> }
> ---------------------------------
I notice that your code doesn't include an import for common.Utils. =
Is=20
this just a cut and paste omission?
------=_NextPart_000_034F_01C70387.5B3F1E80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1476" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Yes, I apologize for =
the=20
typo.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2>~Praveen.</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
<DIV>"David Wegener" <<A=20
href=3D"mailto:wegener@cboenospam.com">wegener@cboenospam.com</A>> =
wrote in=20
message <A=20
=
href=3D"news:eiu033$csi$2@utils.eclipse.org">news:eiu033$csi$2@utils.ecli=
pse.org</A>...</DIV>Praveen=20
wrote:<BR>> I am able to invoke the static method from a regular =
class as=20
follows. <BR>> So the eclipse JDK has the class path etc. setup. I =
suspect=20
its some <BR>> tweak I need to make in the plugin execution=20
environment.<BR>> <BR>> Thanks Praveen.<BR>> =
<BR>>=20
import common.Utils;<BR>> <BR>> public class asd =
{<BR>> =20
<BR>> public static void main(String[] =
args)=20
{<BR> > &a mp;nbsp; =20
Utils.writeToFile("A", "C:\\ad", =
"QWE.txt");<BR>> =20
}<BR>> }<BR>> <BR>> "Praveen" <<A=20
href=3D"mailto:jpk4077@hotmail.com">jpk4077@hotmail.com</A> <<A=20
=
href=3D"mailto:jpk4077@hotmail.com">mailto:jpk4077@hotmail.com</A>>>=
;=20
wrote<BR>> in message <A=20
=
href=3D"news:eitmt9$lvs$1@utils.eclipse.org">news:eitmt9$lvs$1@utils.ecli=
pse.org</A>...<BR>> =20
Hi,<BR>> =
<BR>> I=20
am not sure why but I am not able to invoke a static function=20
from<BR>> within a popupmenu plugin. common =
is=20
another package in the same<BR>> plugin =
project. I=20
am attaching the code where I am invoking a=20
static<BR>> function of another class =
Utils. The=20
output only shows "BEFORE".<BR> > =2 0
<BR>> On debug, earlier eclipse showed me a =
class=20
not found error, now it<BR>> does not show =
me=20
anything. I have done a project clean and a=20
full<BR>> compile and the class files are =
present=20
in the right directory.<BR> > =2 0
<BR>> Tx =
Praveen.<BR>> =20
---------------------------------<BR>> =
package=20
common;<BR>> =
<BR>> =20
public class Utils =
{<BR> > &a mp;nbsp; =20
public static void writeToFile(String str, String=20
=
fileLocation,<BR> > &a mp;nbsp; &nbs=
p; &nbs p; =20
String fileName)=20
=
{<BR> > &a mp;nbsp; &nbs=
p; =20
System.out.println("INSIDE..." + str + " :: " +=20
fileName);<BR> > &a mp;nbsp; =20
}<BR>> }<BR>> =20
---------------------------------<BR>> =
package=20
plugin.actions;<BR>> import=20
org.eclipse.core.resources.IContainer;<BR>> =
import=20
org.eclipse.core.resources.IFile;<BR>> =
import=20
org.eclipse.core.resources.IProject;<BR>> =
import=20
org.eclipse.core.resources.IResource;<BR>> =
import=20
=
org.eclipse.core.resources.IncrementalProjectBuilder;<BR>> =
=20
import =
org.eclipse.core.runtime.CoreException;<BR>> =20
import =
org.eclipse.jface.action.IAction;<BR>> =20
import =
org.eclipse.jface.viewers.ISelection;<BR>> =20
import=20
=
org.eclipse.jface.viewers.IStructuredSelection;<BR>> =
=20
import org.eclipse.ui.IActionDelegate;<BR>> =
import=20
org.eclipse.ui.IObjectActionDelegate;<BR>> =
import=20
org.eclipse.ui.IWorkbenchPart;<BR> > =2 0
<BR>> public class ConvertAction implements =
IObjectActionDelegate=20
{<BR> > &a mp;nbsp; public void=20
run(IAction action)=20
=
{<BR> > &a mp;nbsp; &nbs=
p; =20
if (!m_Selection.isEmpty())=20
=
{<BR> > &a mp;nbsp; &nbs=
p; =20
IStructuredSelection sel =3D=20
(IStructuredSelection)<BR>> =20
=
m_Selection;<BR> > &a mp;nbsp;  =
;   ; =20
Object obj =3D=20
=
sel.getFirstElement();<BR> > &a mp;nbsp; &=
nbsp; & nbsp; =20
if (obj instanceof IFile)=20
=
{<BR> > &a mp;nbsp; &nbs=
p; &nbs p; =20
IFile file =3D (IFile)=20
=
obj;<BR> > &a mp;nbsp; &=
nbsp; & nbsp; =20
IContainer cont =3D=20
=
file.getParent();<BR> > &a mp;nbsp; =
=
String fileName =3D=20
=
file.getName();<BR> > &a mp;nbsp; &n=
bsp; &n bsp; =20
String location =3D=20
=
file.getLocation().toOSString();<BR> > &a mp;nb=
sp; &nb sp; &nb s=
p; =20
String fileDir =3D location.substring(0,=20
=
location.length()<BR> > &a mp;nbsp; =
&=
nbsp; & nbsp; =20
- fileName.length() -=20
=
1);<BR> > &a mp;nbsp; &n=
bsp; &n bsp; =20
String str =3D "TEXT";<BR>> =20
=
System.out.println("BEFORE");<BR> > &a mp;nbsp;=
&=
nbsp; =20
Utils.writeToFile(str, fileDir, =
"MyFile.txt");<BR>> =20
=
System.out.println("AFTER");<BR> > &a mp;nbsp;&=
nbsp; & nbsp; =20
=
}<BR> > &a mp;nbsp; &nbs=
p; =20
}<BR> > &a mp;nbsp; =20
}<BR> > &a mp;nbsp;=20
}<BR>> }<BR>> =20
---------------------------------<BR>I notice that your code doesn't =
include=20
an import for common.Utils. Is <BR>this just a cut and paste=20
omission?</BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_034F_01C70387.5B3F1E80--
|
|
|
Re: Problem invoking static methods. [message #309792 is a reply to message #309791] |
Thu, 09 November 2006 01:48   |
Eclipse User |
|
|
|
Originally posted by: jpk4077.hotmail.com
This is a multi-part message in MIME format.
------=_NextPart_000_03C2_01C703A1.38DD8C90
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I suspect its because the plugin is in package plugin.actions and the =
utils class is in common package. common and plugin are at the same =
hierarchy but the execution considers plugin.action as the root and =
looks for common.utils inside it.
I tried adding the bin and src directories to classpath in the runtime =
tab but that doesent help. Any other ideas?
Thanks Praveen.
"Praveen" <jpk4077@hotmail.com> wrote in message =
news:eiu85n$ah4$1@utils.eclipse.org...
Yes, I apologize for the typo.
~Praveen.
"David Wegener" <wegener@cboenospam.com> wrote in message =
news:eiu033$csi$2@utils.eclipse.org...
Praveen wrote:
> I am able to invoke the static method from a regular class as =
follows.=20
> So the eclipse JDK has the class path etc. setup. I suspect its =
some=20
> tweak I need to make in the plugin execution environment.
> =20
> Thanks Praveen.
> =20
> import common.Utils;
> =20
> public class asd {
> =20
> public static void main(String[] args) {
> Utils.writeToFile("A", "C:\\ad", "QWE.txt");
> }
> }
>=20
> "Praveen" <jpk4077@hotmail.com <mailto:jpk4077@hotmail.com>> =
wrote
> in message news:eitmt9$lvs$1@utils.eclipse.org...
> Hi,
> =20
> I am not sure why but I am not able to invoke a static =
function from
> within a popupmenu plugin. common is another package in the =
same
> plugin project. I am attaching the code where I am invoking a =
static
> function of another class Utils. The output only shows =
"BEFORE".
> =20
> On debug, earlier eclipse showed me a class not found error, =
now it
> does not show me anything. I have done a project clean and a =
full
> compile and the class files are present in the right =
directory.
> =20
> Tx Praveen.
> ---------------------------------
> package common;
> =20
> public class Utils {
> public static void writeToFile(String str, String =
fileLocation,
> String fileName) {
> System.out.println("INSIDE..." + str + " :: " + =
fileName);
> }
> }
> ---------------------------------
> package plugin.actions;
> import org.eclipse.core.resources.IContainer;
> import org.eclipse.core.resources.IFile;
> import org.eclipse.core.resources.IProject;
> import org.eclipse.core.resources.IResource;
> import org.eclipse.core.resources.IncrementalProjectBuilder;
> import org.eclipse.core.runtime.CoreException;
> import org.eclipse.jface.action.IAction;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.IStructuredSelection;
> import org.eclipse.ui.IActionDelegate;
> import org.eclipse.ui.IObjectActionDelegate;
> import org.eclipse.ui.IWorkbenchPart;
> =20
> public class ConvertAction implements IObjectActionDelegate {
> public void run(IAction action) {
> if (!m_Selection.isEmpty()) {
> IStructuredSelection sel =3D =
(IStructuredSelection)
> m_Selection;
> Object obj =3D sel.getFirstElement();
> if (obj instanceof IFile) {
> IFile file =3D (IFile) obj;
> IContainer cont =3D file.getParent();
> String fileName =3D file.getName();
> String location =3D =
file.getLocation().toOSString();
> String fileDir =3D location.substring(0, =
location.length()
> - fileName.length() - 1);
> String str =3D "TEXT";
> System.out.println("BEFORE");
> Utils.writeToFile(str, fileDir, =
"MyFile.txt");
> System.out.println("AFTER");
> }
> }
> }
> }
> }
> ---------------------------------
I notice that your code doesn't include an import for common.Utils. =
Is=20
this just a cut and paste omission?
------=_NextPart_000_03C2_01C703A1.38DD8C90
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1476" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>I suspect its because =
the plugin is=20
in package plugin.actions and the utils class is in common package. =
common and=20
plugin are at the same hierarchy but the execution considers =
plugin.action as=20
the root and looks for common.utils inside it.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>I tried adding the =
bin and src=20
directories to classpath in the runtime tab but that doesent help. Any =
other=20
ideas?</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Thanks =
Praveen.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Praveen" <<A=20
href=3D"mailto:jpk4077@hotmail.com">jpk4077@hotmail.com</A>> wrote =
in message=20
<A=20
=
href=3D"news:eiu85n$ah4$1@utils.eclipse.org">news:eiu85n$ah4$1@utils.ecli=
pse.org</A>...</DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Yes, I apologize =
for the=20
typo.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 =
size=3D2>~Praveen.</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
<DIV>"David Wegener" <<A=20
=
href=3D"mailto:wegener@cboenospam.com">wegener@cboenospam.com</A>> =
wrote in=20
message <A=20
=
href=3D"news:eiu033$csi$2@utils.eclipse.org">news:eiu033$csi$2@utils.ecli=
pse.org</A>...</DIV>Praveen=20
wrote:<BR>> I am able to invoke the static method from a regular =
class as=20
follows. <BR>> So the eclipse JDK has the class path etc. setup. =
I=20
suspect its some <BR>> tweak I need to make in the plugin =
execution=20
environment.<BR>> <BR>> Thanks Praveen.<BR>> =
<BR>>=20
import common.Utils;<BR>> <BR>> public class asd =
{<BR>> =20
<BR>> public static void main(String[] =
args)=20
{<BR> > &a mp;nbsp; =20
Utils.writeToFile("A", "C:\\ad", =
"QWE.txt");<BR>> =20
}<BR>> }<BR>> <BR>> "Praveen" =
<<A=20
href=3D"mailto:jpk4077@hotmail.com">jpk4077@hotmail.com</A> <<A=20
=
href=3D"mailto:jpk4077@hotmail.com">mailto:jpk4077@hotmail.com</A>>>=
;=20
wrote<BR>> in message <A=20
=
href=3D"news:eitmt9$lvs$1@utils.eclipse.org">news:eitmt9$lvs$1@utils.ecli=
pse.org</A>...<BR>> =20
Hi,<BR>> =
<BR>> I=20
am not sure why but I am not able to invoke a static function=20
from<BR>> within a popupmenu plugin. =
common is=20
another package in the same<BR>> plugin =
project.=20
I am attaching the code where I am invoking a=20
static<BR>> function of another class =
Utils. The=20
output only shows "BEFORE".<BR> > =2 0
<BR>> On debug, earlier eclipse showed me =
a class=20
not found error, now it<BR>> does not =
show me=20
anything. I have done a project clean and a=20
full<BR>> compile and the class files are =
present=20
in the right directory.<BR> > =2 0
<BR>> Tx =
Praveen.<BR>> =20
---------------------------------<BR>> =
package=20
common;<BR> > =2 0
<BR>> public class Utils=20
{<BR> > &a mp;nbsp; public =
static void=20
writeToFile(String str, String=20
=
fileLocation,<BR> > &a mp;nbsp; &nbs=
p; &nbs p; =20
String fileName)=20
=
{<BR> > &a mp;nbsp; &nbs=
p; =20
System.out.println("INSIDE..." + str + " :: " +=20
fileName);<BR> > &a mp;nbsp; =20
}<BR>> }<BR>> =20
---------------------------------<BR>> =
package=20
plugin.actions;<BR>> import=20
=
org.eclipse.core.resources.IContainer;<BR>> =20
import =
org.eclipse.core.resources.IFile;<BR>> =20
import =
org.eclipse.core.resources.IProject;<BR>> =20
import =
org.eclipse.core.resources.IResource;<BR>> =20
import=20
=
org.eclipse.core.resources.IncrementalProjectBuilder;<BR>> =
=20
import=20
=
org.eclipse.core.runtime.CoreException;<BR>> =20
import =
org.eclipse.jface.action.IAction;<BR>> =20
import =
org.eclipse.jface.viewers.ISelection;<BR>> =20
import=20
=
org.eclipse.jface.viewers.IStructuredSelection;<BR>> =
=20
import =
org.eclipse.ui.IActionDelegate;<BR>> =20
import =
org.eclipse.ui.IObjectActionDelegate;<BR>> =20
import =
org.eclipse.ui.IWorkbenchPart;<BR> > =2 0
<BR>> public class ConvertAction =
implements=20
IObjectActionDelegate=20
{<BR> > &a mp;nbsp; public =
void=20
run(IAction action)=20
=
{<BR> > &a mp;nbsp; &nbs=
p; =20
if (!m_Selection.isEmpty())=20
=
{<BR> > &a mp;nbsp; &nbs=
p; =20
IStructuredSelection sel =3D=20
(IStructuredSelection)<BR>> =20
=
m_Selection;<BR> > &a mp;nbsp;  =
;   ; =20
Object obj =3D=20
=
sel.getFirstElement();<BR> > &a mp;nbsp; &=
nbsp; & nbsp; =20
if (obj instanceof IFile)=20
=
{<BR> > &a mp;nbsp; &nbs=
p; &nbs p; =20
IFile file =3D (IFile)=20
=
obj;<BR> > &a mp;nbsp; &=
nbsp; & nbsp; =20
IContainer cont =3D=20
=
file.getParent();<BR> > &a mp;nbsp; =
=
String fileName =3D=20
=
file.getName();<BR> > &a mp;nbsp; &n=
bsp; &n bsp; =20
String location =3D=20
=
file.getLocation().toOSString();<BR> > &a mp;nb=
sp; &nb sp; &nb s=
p; =20
String fileDir =3D location.substring(0,=20
=
location.length()<BR> > &a mp;nbsp; =
&=
nbsp; & nbsp; =20
- fileName.length() -=20
=
1);<BR> > &a mp;nbsp; &n=
bsp; &n bsp; =20
String str =3D "TEXT";<BR>> =20
=
System.out.println("BEFORE");<BR> > &a mp;nbsp;=
&=
nbsp; =20
Utils.writeToFile(str, fileDir,=20
"MyFile.txt");<BR>> =20
=
System.out.println("AFTER");<BR> > &a mp;nbsp;&=
nbsp; & nbsp; =20
=
}<BR> > &a mp;nbsp; &nbs=
p; =20
}<BR> > &a mp;nbsp; =20
}<BR> > &a mp;nbsp;=20
}<BR>> }<BR>> =20
---------------------------------<BR>I notice that your code doesn't =
include=20
an import for common.Utils. Is <BR>this just a cut and paste=20
omission?</BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_03C2_01C703A1.38DD8C90--
|
|
|
Re: Problem invoking static methods. [message #309806 is a reply to message #309792] |
Thu, 09 November 2006 10:13   |
Eclipse User |
|
|
|
Praveen,
in the OSGi runtime, your plugin.actions bundle can only load classes
from bundles that it said it required.
What you need to do is for the common bundle to add an Export-Package
for its utils package in its manifest.mf file.
Then plugin.actions needs to either Require-Bundle: common, or
Import-Package: common.utils in its manifest.
-Andrew
Praveen wrote:
> I suspect its because the plugin is in package plugin.actions and the
> utils class is in common package. common and plugin are at the same
> hierarchy but the execution considers plugin.action as the root and
> looks for common.utils inside it.
>
> I tried adding the bin and src directories to classpath in the runtime
> tab but that doesent help. Any other ideas?
>
> Thanks Praveen.
>
> "Praveen" <jpk4077@hotmail.com <mailto:jpk4077@hotmail.com>> wrote
> in message news:eiu85n$ah4$1@utils.eclipse.org...
> Yes, I apologize for the typo.
>
> ~Praveen.
>
> "David Wegener" <wegener@cboenospam.com
> <mailto:wegener@cboenospam.com>> wrote in message
> news:eiu033$csi$2@utils.eclipse.org...
> Praveen wrote:
> > I am able to invoke the static method from a regular class as
> follows.
> > So the eclipse JDK has the class path etc. setup. I suspect
> its some
> > tweak I need to make in the plugin execution environment.
> >
> > Thanks Praveen.
> >
> > import common.Utils;
> >
> > public class asd {
> >
> > public static void main(String[] args) {
> > Utils.writeToFile("A", "C:\\ad", "QWE.txt");
> > }
> > }
> >
> > "Praveen" <jpk4077@hotmail.com
> <mailto:jpk4077@hotmail.com> <mailto:jpk4077@hotmail.com>> wrote
> > in message news:eitmt9$lvs$1@utils.eclipse.org...
> > Hi,
> >
> > I am not sure why but I am not able to invoke a static
> function from
> > within a popupmenu plugin. common is another package in
> the same
> > plugin project. I am attaching the code where I am
> invoking a static
> > function of another class Utils. The output only shows
> "BEFORE".
> >
> > On debug, earlier eclipse showed me a class not found
> error, now it
> > does not show me anything. I have done a project clean
> and a full
> > compile and the class files are present in the right
> directory.
> >
> > Tx Praveen.
> > ---------------------------------
> > package common;
> >
> > public class Utils {
> > public static void writeToFile(String str, String
> fileLocation,
> > String fileName) {
> > System.out.println("INSIDE..." + str + " :: " +
> fileName);
> > }
> > }
> > ---------------------------------
> > package plugin.actions;
> > import org.eclipse.core.resources.IContainer;
> > import org.eclipse.core.resources.IFile;
> > import org.eclipse.core.resources.IProject;
> > import org.eclipse.core.resources.IResource;
> > import org.eclipse.core.resources.IncrementalProjectBuilder;
> > import org.eclipse.core.runtime.CoreException;
> > import org.eclipse.jface.action.IAction;
> > import org.eclipse.jface.viewers.ISelection;
> > import org.eclipse.jface.viewers.IStructuredSelection;
> > import org.eclipse.ui.IActionDelegate;
> > import org.eclipse.ui.IObjectActionDelegate;
> > import org.eclipse.ui.IWorkbenchPart;
> >
> > public class ConvertAction implements IObjectActionDelegate {
> > public void run(IAction action) {
> > if (!m_Selection.isEmpty()) {
> > IStructuredSelection sel = (IStructuredSelection)
> > m_Selection;
> > Object obj = sel.getFirstElement();
> > if (obj instanceof IFile) {
> > IFile file = (IFile) obj;
> > IContainer cont = file.getParent();
> > String fileName = file.getName();
> > String location =
> file.getLocation().toOSString();
> > String fileDir = location.substring(0,
> location.length()
> > - fileName.length() - 1);
> > String str = "TEXT";
> > System.out.println("BEFORE");
> > Utils.writeToFile(str, fileDir,
> "MyFile.txt");
> > System.out.println("AFTER");
> > }
> > }
> > }
> > }
> > }
> > ---------------------------------
> I notice that your code doesn't include an import for
> common.Utils. Is
> this just a cut and paste omission?
|
|
|
Re: Problem invoking static methods. [message #309881 is a reply to message #309806] |
Fri, 10 November 2006 12:11  |
Eclipse User |
|
|
|
Originally posted by: jpk4077.hotmail.com
This is a multi-part message in MIME format.
------=_NextPart_000_017B_01C704C1.600F1970
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi Andrew,
I made another hello world plugin with just the same hierarchy of plugin =
and other classes and I am able to access the plugin static method =
without doing an export-Package or a required-Bundle.=20
In my existing project with common, plugin.actions, I added in the =
exported packages tab and the classpath tab. But am still facing the =
same problem
I am not sure what I am missing.
Tx Praveen.
"Andrew Niefer" <aniefer@ca.ibm.com> wrote in message =
news:eivgh2$spj$1@utils.eclipse.org...
Praveen,
in the OSGi runtime, your plugin.actions bundle can only load classes=20
from bundles that it said it required.
What you need to do is for the common bundle to add an Export-Package=20
for its utils package in its manifest.mf file.
Then plugin.actions needs to either Require-Bundle: common, or=20
Import-Package: common.utils in its manifest.
-Andrew
Praveen wrote:
> I suspect its because the plugin is in package plugin.actions and =
the=20
> utils class is in common package. common and plugin are at the same=20
> hierarchy but the execution considers plugin.action as the root and=20
> looks for common.utils inside it.
> =20
> I tried adding the bin and src directories to classpath in the =
runtime=20
> tab but that doesent help. Any other ideas?
> =20
> Thanks Praveen.
>=20
> "Praveen" <jpk4077@hotmail.com <mailto:jpk4077@hotmail.com>> =
wrote
> in message news:eiu85n$ah4$1@utils.eclipse.org...
> Yes, I apologize for the typo.
> =20
> ~Praveen.
>=20
> "David Wegener" <wegener@cboenospam.com
> <mailto:wegener@cboenospam.com>> wrote in message
> news:eiu033$csi$2@utils.eclipse.org...
> Praveen wrote:
> > I am able to invoke the static method from a regular =
class as
> follows.
> > So the eclipse JDK has the class path etc. setup. I =
suspect
> its some
> > tweak I need to make in the plugin execution environment.
> >=20
> > Thanks Praveen.
> >=20
> > import common.Utils;
> >=20
> > public class asd {
> >=20
> > public static void main(String[] args) {
> > Utils.writeToFile("A", "C:\\ad", "QWE.txt");
> > }
> > }
> >
> > "Praveen" <jpk4077@hotmail.com
> <mailto:jpk4077@hotmail.com> <mailto:jpk4077@hotmail.com>> =
wrote
> > in message news:eitmt9$lvs$1@utils.eclipse.org...
> > Hi,
> > =20
> > I am not sure why but I am not able to invoke a =
static
> function from
> > within a popupmenu plugin. common is another package =
in
> the same
> > plugin project. I am attaching the code where I am
> invoking a static
> > function of another class Utils. The output only =
shows
> "BEFORE".
> > =20
> > On debug, earlier eclipse showed me a class not found
> error, now it
> > does not show me anything. I have done a project =
clean
> and a full
> > compile and the class files are present in the right
> directory.
> > =20
> > Tx Praveen.
> > ---------------------------------
> > package common;
> > =20
> > public class Utils {
> > public static void writeToFile(String str, String
> fileLocation,
> > String fileName) {
> > System.out.println("INSIDE..." + str + " :: " =
+
> fileName);
> > }
> > }
> > ---------------------------------
> > package plugin.actions;
> > import org.eclipse.core.resources.IContainer;
> > import org.eclipse.core.resources.IFile;
> > import org.eclipse.core.resources.IProject;
> > import org.eclipse.core.resources.IResource;
> > import =
org.eclipse.core.resources.IncrementalProjectBuilder;
> > import org.eclipse.core.runtime.CoreException;
> > import org.eclipse.jface.action.IAction;
> > import org.eclipse.jface.viewers.ISelection;
> > import =
org.eclipse.jface.viewers.IStructuredSelection;
> > import org.eclipse.ui.IActionDelegate;
> > import org.eclipse.ui.IObjectActionDelegate;
> > import org.eclipse.ui.IWorkbenchPart;
> > =20
> > public class ConvertAction implements =
IObjectActionDelegate {
> > public void run(IAction action) {
> > if (!m_Selection.isEmpty()) {
> > IStructuredSelection sel =3D =
(IStructuredSelection)
> > m_Selection;
> > Object obj =3D sel.getFirstElement();
> > if (obj instanceof IFile) {
> > IFile file =3D (IFile) obj;
> > IContainer cont =3D file.getParent();
> > String fileName =3D file.getName();
> > String location =3D
> file.getLocation().toOSString();
> > String fileDir =3D =
location.substring(0,
> location.length()
> > - fileName.length() - 1);
> > String str =3D "TEXT";
> > System.out.println("BEFORE");
> > Utils.writeToFile(str, fileDir,
> "MyFile.txt");
> > System.out.println("AFTER");
> > }
> > }
> > }
> > }
> > }
> > ---------------------------------
> I notice that your code doesn't include an import for
> common.Utils. Is
> this just a cut and paste omission?
------=_NextPart_000_017B_01C704C1.600F1970
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1476" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DCourier><FONT color=3D#000080 size=3D2>Hi=20
Andrew,</FONT></FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>I made another hello =
world plugin=20
with just the same hierarchy of plugin and other classes and I am able =
to access=20
the plugin static method without doing an export-Package or a =
required-Bundle.=20
</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>In my existing =
project with common,=20
plugin.actions, I added in the exported packages tab and the classpath =
tab. But=20
am still facing the same problem</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>I am not sure what I =
am=20
missing.</FONT></DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier color=3D#000080 size=3D2>Tx =
Praveen.</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Andrew Niefer" <<A=20
href=3D"mailto:aniefer@ca.ibm.com">aniefer@ca.ibm.com</A>> wrote in =
message=20
<A=20
=
href=3D"news:eivgh2$spj$1@utils.eclipse.org">news:eivgh2$spj$1@utils.ecli=
pse.org</A>...</DIV>Praveen,<BR>in=20
the OSGi runtime, your plugin.actions bundle can only load classes =
<BR>from=20
bundles that it said it required.<BR>What you need to do is for the =
common=20
bundle to add an Export-Package <BR>for its utils package in its =
manifest.mf=20
file.<BR>Then plugin.actions needs to either Require-Bundle: common, =
or=20
<BR>Import-Package: common.utils in its =
manifest.<BR><BR>-Andrew<BR>Praveen=20
wrote:<BR>> I suspect its because the plugin is in package =
plugin.actions=20
and the <BR>> utils class is in common package. common and plugin =
are at=20
the same <BR>> hierarchy but the execution considers plugin.action =
as the=20
root and <BR>> looks for common.utils inside it.<BR>> =
<BR>> I=20
tried adding the bin and src directories to classpath in the runtime =
<BR>>=20
tab but that doesent help. Any other ideas?<BR>> <BR>> =
Thanks=20
Praveen.<BR>> <BR>> "Praveen" <<A=20
href=3D"mailto:jpk4077@hotmail.com">jpk4077@hotmail.com</A> <<A=20
=
href=3D"mailto:jpk4077@hotmail.com">mailto:jpk4077@hotmail.com</A>>>=
;=20
wrote<BR>> in message <A=20
=
href=3D"news:eiu85n$ah4$1@utils.eclipse.org">news:eiu85n$ah4$1@utils.ecli=
pse.org</A>...<BR>> =20
Yes, I apologize for the typo.<BR> > =2 0
<BR>> ~Praveen.<BR>>=20
<BR> > &a mp;nbsp; "David =
Wegener"=20
<<A=20
=
href=3D"mailto:wegener@cboenospam.com">wegener@cboenospam.com</A><BR>>=
=20
<<A=20
=
href=3D"mailto:wegener@cboenospam.com">mailto:wegener@cboenospam.com</A>&=
gt;>=20
wrote in =
message<BR> > &a mp;nbsp; <A=20
=
href=3D"news:eiu033$csi$2@utils.eclipse.org">news:eiu033$csi$2@utils.ecli=
pse.org</A>...<BR> > &a mp;nbsp; =20
Praveen =
wrote:<BR> > &a mp;nbsp; =20
> I am able to invoke the static method from a regular class=20
as<BR> > &a mp;nbsp; =20
follows.<BR> > &a mp;nbsp; =
> So=20
the eclipse JDK has the class path etc. setup. I=20
suspect<BR> > &a mp;nbsp; its=20
some<BR> > &a mp;nbsp; =
> tweak=20
I need to make in the plugin execution=20
=
environment.<BR> > &a mp;nbsp;  =
;=20
> <BR> > &a mp;nbsp; =
>=20
Thanks =
Praveen.<BR> > &a mp;nbsp; =20
> <BR> > &a mp;nbsp; =
>=20
import=20
=
common.Utils;<BR> > &a mp;nbsp; &nbs=
p;=20
> <BR> > &a mp;nbsp; =
>=20
public class asd=20
{<BR> > &a mp;nbsp; >=20
<BR> > &a mp;nbsp; =20
> public static void main(String[] args)=20
{<BR> > &a mp;nbsp; =20
> &a mp;nbsp; =
Utils.writeToFile("A",=20
"C:\\ad",=20
=
"QWE.txt");<BR> > &a mp;nbsp; =
=20
> =20
}<BR> > &a mp;nbsp; >=20
}<BR> > &a mp;nbsp; =20
><BR> > &a mp;nbsp; =20
> "Praveen" <<A=20
=
href=3D"mailto:jpk4077@hotmail.com">jpk4077@hotmail.com</A><BR>> =
=20
<<A =
href=3D"mailto:jpk4077@hotmail.com">mailto:jpk4077@hotmail.com</A>>=20
<<A=20
=
href=3D"mailto:jpk4077@hotmail.com">mailto:jpk4077@hotmail.com</A>>>=
;=20
wrote<BR> > &a mp;nbsp; =20
> in message <A=20
=
href=3D"news:eitmt9$lvs$1@utils.eclipse.org">news:eitmt9$lvs$1@utils.ecli=
pse.org</A>...<BR> > &a mp;nbsp; &nb=
sp;=20
> =20
Hi,<BR> > &a mp;nbsp; =20
> =20
<BR> > &a mp;nbsp; =20
> I am not sure why but I am not able to =
invoke a=20
static<BR> > &a mp;nbsp; =
function=20
from<BR> > &a mp;nbsp; =20
> within a popupmenu plugin. common is =
another=20
package in<BR> > &a mp;nbsp; the =
same<BR> > &a mp;nbsp; =20
> plugin project. I am attaching the code =
where I=20
am<BR> > &a mp;nbsp; invoking a=20
static<BR> > &a mp;nbsp; =20
> function of another class Utils. The =
output only=20
shows<BR> > &a mp;nbsp; =20
=
"BEFORE".<BR> > &a mp;nbsp; =20
> =20
<BR> > &a mp;nbsp; =20
> On debug, earlier eclipse showed me a =
class not=20
found<BR> > &a mp;nbsp; error, =
now=20
it<BR> > &a mp;nbsp; =20
> does not show me anything. I have done a =
project=20
clean<BR> > &a mp;nbsp; and a=20
full<BR> > &a mp;nbsp; =20
> compile and the class files are present =
in the=20
right<BR> > &a mp;nbsp; =20
=
directory.<BR> > &a mp;nbsp; =
> =20
<BR> > &a mp;nbsp; =20
> Tx=20
Praveen.<BR> > &a mp;nbsp; =
> =20
=
---------------------------------<BR> > &a mp;n=
bsp; =20
> package=20
common;<BR> > &a mp;nbsp; =20
> =20
<BR> > &a mp;nbsp; =20
> public class Utils=20
{<BR> > &a mp;nbsp; =20
> &a mp;nbsp; public static =
void=20
writeToFile(String str,=20
String<BR> > &a mp;nbsp; =20
=
fileLocation,<BR> > &a mp;nbsp; &nbs=
p;=20
=
> &a mp;nbsp; &a mp;nb=
sp; =20
String fileName)=20
{<BR> > &a mp;nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp;=20
System.out.println("INSIDE..." + str + " :: "=20
+<BR> > &a mp;nbsp; =20
=
fileName);<BR> > &a mp;nbsp; =
> &a mp;nbsp; =20
}<BR> > &a mp;nbsp; =20
> =20
}<BR> > &a mp;nbsp; =20
> =20
=
---------------------------------<BR> > &a mp;n=
bsp; =20
> package=20
=
plugin.actions;<BR> > &a mp;nbsp; &n=
bsp;=20
> import=20
=
org.eclipse.core.resources.IContainer;<BR>> &nb=
sp; =20
> import=20
=
org.eclipse.core.resources.IFile;<BR> > &a mp;n=
bsp; =20
> import=20
=
org.eclipse.core.resources.IProject;<BR>>  =
; =20
> import=20
=
org.eclipse.core.resources.IResource;<BR>> &nbs=
p; =20
> import=20
=
org.eclipse.core.resources.IncrementalProjectBuilder;<BR>> =
=20
> import=20
=
org.eclipse.core.runtime.CoreException;<BR>> &n=
bsp; =20
> import=20
=
org.eclipse.jface.action.IAction;<BR> > &a mp;n=
bsp; =20
> import=20
=
org.eclipse.jface.viewers.ISelection;<BR>> &nbs=
p; =20
> import=20
=
org.eclipse.jface.viewers.IStructuredSelection;<BR>> =
=20
> import=20
=
org.eclipse.ui.IActionDelegate;<BR> > &a mp;nbs=
p; =20
> import=20
=
org.eclipse.ui.IObjectActionDelegate;<BR>> &nbs=
p; =20
> import=20
=
org.eclipse.ui.IWorkbenchPart;<BR> > &a mp;nbsp=
; =20
> =20
<BR> > &a mp;nbsp; =20
> public class ConvertAction implements=20
IObjectActionDelegate=20
{<BR> > &a mp;nbsp; =20
> &a mp;nbsp; public void =
run(IAction=20
action) =
{<BR> > &a mp;nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp;=20
if (!m_Selection.isEmpty())=20
{<BR> > &a mp;nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp; =20
IStructuredSelection sel =3D=20
=
(IStructuredSelection)<BR> > &a mp;nbsp; &=
nbsp; =20
> =20
=
m_Selection;<BR> > &a mp;nbsp;  =
;=20
=
> &a mp;nbsp; &a mp;nb=
sp; =20
Object obj =3D=20
=
sel.getFirstElement();<BR> > &a mp;nbsp; &=
nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp; =20
if (obj instanceof IFile)=20
{<BR> > &a mp;nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; =20
IFile file =3D (IFile)=20
obj;<BR> > &a mp;nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; =20
IContainer cont =3D=20
=
file.getParent();<BR> > &a mp;nbsp; =
=20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; =20
String fileName =3D=20
=
file.getName();<BR> > &a mp;nbsp; &n=
bsp;=20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; =20
String location =
=3D<BR> > &a mp;nbsp; =20
=
file.getLocation().toOSString();<BR> > &a mp;nb=
sp; =20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; =20
String fileDir =3D=20
=
location.substring(0,<BR> > &a mp;nbsp; &n=
bsp;=20
=
location.length()<BR> > &a mp;nbsp; =
=20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; &nb s=
p; =20
- fileName.length() -=20
1);<BR> > &a mp;nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; =20
String str =3D=20
"TEXT";<BR> > &a mp;nbsp; =20
> =20
=
System.out.println("BEFORE");<BR> > &a mp;nbsp;=
=20
=
> &a mp;nbsp; &a mp;nb=
sp; &nb sp; &nb s=
p;=20
Utils.writeToFile(str,=20
fileDir,<BR> > &a mp;nbsp; =20
=
"MyFile.txt");<BR> > &a mp;nbsp; &nb=
sp;=20
> =20
=
System.out.println("AFTER");<BR> > &a mp;nbsp;&=
nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp; =20
}<BR> > &a mp;nbsp; =20
=
> &a mp;nbsp; &a mp;nb=
sp;=20
}<BR> > &a mp;nbsp; =20
> &a mp;nbsp; =20
}<BR> > &a mp;nbsp; =20
> &a mp;nbsp;=20
}<BR> > &a mp;nbsp; =20
> =20
}<BR> > &a mp;nbsp; =20
> =20
=
---------------------------------<BR> > &a mp;n=
bsp; =20
I notice that your code doesn't include an import=20
for<BR> > &a mp;nbsp; =20
common.Utils. =
Is<BR> > &a mp;nbsp; =20
this just a cut and paste omission?</BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_017B_01C704C1.600F1970--
|
|
|
Goto Forum:
Current Time: Thu May 08 21:46:24 EDT 2025
Powered by FUDForum. Page generated in 0.03589 seconds
|