Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Missing bin suffix at getCodeSource().getLocation()
Missing bin suffix at getCodeSource().getLocation() [message #654360] Tue, 15 February 2011 11:56 Go to next message
Thomas Pilarski is currently offline Thomas PilarskiFriend
Messages: 6
Registered: November 2010
Location: Hannover
Junior Member
I am developing a eclipse plugin and trying to get the location uri of the corresponding class path. It works fine with the exported jar file. As I am still developing the plugin, I cannot use debug features with a jar file. If I start the plugin direct, the following code return the project root path, without the needed bin suffix.

I have created a new Hello World project, which just returns the location of the code source and the bin suffix is still missing.

this.getClass().getProtectionDomain().getCodeSource().getLoc ation().toString()

I am using the Helios Service Release 1 (20100917-0705) and no update are available.

I have searches for a long time on google, but have not found any solution. Have someone a hint for me for solving my problem?

Thomas
Re: Missing bin suffix at getCodeSource().getLocation() [message #654363 is a reply to message #654360] Tue, 15 February 2011 12:32 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/15/2011 06:56 AM, Thomas Pilarski wrote:
> I am developing a eclipse plugin and trying to get the location uri of
> the corresponding class path.

What are you trying to do, exactly? You have a project in eclipse that
you are currently working on, and you want to run "what" on it that you
need to find its classpath? Do you want to run it in your eclipse on
your working project?

Or you are going to launch an inner Eclipse app? Java app? and you'd
like to operate on what from the inner?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Missing bin suffix at getCodeSource().getLocation() [message #654365 is a reply to message #654363] Tue, 15 February 2011 12:50 Go to previous messageGo to next message
Thomas Pilarski is currently offline Thomas PilarskiFriend
Messages: 6
Registered: November 2010
Location: Hannover
Junior Member
Paul Webster wrote on Tue, 15 February 2011 07:32

What are you trying to do, exactly? You have a project in eclipse that
you are currently working on, and you want to run "what" on it that you
need to find its classpath? Do you want to run it in your eclipse on
your working project?



I am creating a non eclipse data transformation with antlr. The transformation classes are loaded dynamically for all parts, during creation of the transformator. This part is already working as a standalone java project, as file://... and jar resource.

This transformation is used in a graphical and textual editor and it works fine, when I import the transformation project as jar file and add the classpath to the editors, as the the package is at the top level of the jar file.

To allow debugging of the transformator within the eclipse run-time environment I have changes the project type of the transformator to a plugin project and started the run-time environment. The transformation parts are not found anymore, as the binary files are store in $(projectRoot)/bin the getCodeSource().getLocation() returns $(projectRoot) only.

Paul Webster wrote on Tue, 15 February 2011 07:32

Or you are going to launch an inner Eclipse app? Java app? and you'd
like to operate on what from the inner?



The transformation package is used in a standalone application and a eclipse plugin. The second does only work with a jar file, not a normal (plugin) project.


Re: Missing bin suffix at getCodeSource().getLocation() [message #654382 is a reply to message #654365] Tue, 15 February 2011 14:07 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

So you are in an eclipse environment, and you need to access files from
within the project?

Option one: If your tool is an eclipse plugin, use core.resources to
access projects in the workspace. But it sounds like you need something
that doesn't care about an eclipse workspace.

Option two: You've created your project, launched an inner, and want it
to find the files correctly from your plugin. Use Bundle.getEntry(*)
which returns a URL (which returns an InputStream). It will return a
useful URL/InputStream when run from a project in eclipse or after your
project has been deployed as a <plugin>.jar

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Missing bin suffix at getCodeSource().getLocation() [message #654402 is a reply to message #654382] Tue, 15 February 2011 15:31 Go to previous messageGo to next message
Thomas Pilarski is currently offline Thomas PilarskiFriend
Messages: 6
Registered: November 2010
Location: Hannover
Junior Member
I will explain my project dependencies.

STI-Project:
I am using simple transformation infrastructure for translating between different models. It scans within a given package name for classes with a runtime annotation. Checks theses classes for a method with a given name and put the type of the first parameter to as key and a callback object as value in a look-up map.

ATransformation-Project:
This project provides the transformation classes for the model elements.

Both projects are not eclipse plug-ins, therefore they cannot use the eclipse platform framework.

AModelEditor-Project:
Is an gmf editor, which uses the STI and ATransformation projects for a transformation.

The junit tests for STI- and ATransformation-projects works fine, while using the eclipse project or the exported project jars.

I have converted the STI- and ATransformation-projects as eclise plugins, to add these as dependencies in the AModelEditor project. If I export the STI- and ATransformation-Project as "Deployable plug-in and fragments", the transformation works fine, as the package is exported to the root of the jar file.

If I just start the AModelEditor-Plugin with the STI- and ATransformation-projects as dependencies for debugging purposes, the transformation classes are not found, as the AnAnnotationClass.class.getProtectionDomain().getCodeSource( ).getLocation() does not return the binary folder ($project/bin), but the project root. AnAnnotationClass.class is part of the ATransformation-project, which contains the transformation classes.

I have tried a lot of changes in plugin.xml or the MANIFEST.MF, but with no success. And all resources on the web I have found, tells that ....getCodeSource().getLocation() returns the binary folder. On my machine it's the project root.
How can I change the plugin.xml or the MANIFEST.MF, so that the AnAnnotationClass.class.getProtectionDomain().getCodeSource( ).getLocation() returns the binaryFolder and not the project root folder?
Re: Missing bin suffix at getCodeSource().getLocation() [message #654449 is a reply to message #654402] Tue, 15 February 2011 20:12 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/15/2011 10:31 AM, Thomas Pilarski wrote:
>
> I have tried a lot of changes in plugin.xml or the MANIFEST.MF, but with
> no success. And all resources on the web I have found, tells that
> ....getCodeSource().getLocation() returns the binary folder. On my
> machine it's the project root. How can I change the plugin.xml or the
> MANIFEST.MF, so that the
> AnAnnotationClass.class.getProtectionDomain().getCodeSource(
> ).getLocation() returns the binaryFolder and not the project root folder?
>

AFAIK you cannot. That information is coming from the OSGi classloader
(which isn't in any way based on a real classpath). When eclipse
launches and includes projects from your workspace as plugins, it is
launched in a special mode for projects that are plugins and passed in a
dev.properties file that instructs it to load classes from that project
in a special place. In my example, that file has entries like:
org.eclipse.e4.core.services=bin
org.eclipse.e4.ui.css.jface=bin

etc.

So the problem is you need to have the STI plugin walk classes provided
by the ATransformation plugin so you can scan for runtime annotations,
and then apply that to the AModelEditor project?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Missing bin suffix at getCodeSource().getLocation() [message #654566 is a reply to message #654449] Wed, 16 February 2011 10:43 Go to previous messageGo to next message
Thomas Pilarski is currently offline Thomas PilarskiFriend
Messages: 6
Registered: November 2010
Location: Hannover
Junior Member
Paul Webster wrote on Tue, 15 February 2011 21:12
So the problem is you need to have the STI plugin walk classes provided
by the ATransformation plugin so you can scan for runtime annotations,
and then apply that to the AModelEditor project?


I don't understand the apply. The AModelEditor uses the ATransformation plugin to transform the edited model. I am using aClassLoader.getResources(package.replace('.', '/')) and directory search to find the classes.

The real problem depends on this How to list files in a bundleresource:// URL?
And it seems there is no solution for me, I tried to go around this problem with .getCodeSource().getLocation().

Perhaps there is a very simple solution. Is there a way to use the normal java project (no plug-in) in eclipse plug-in projects, including debugging and hot code replace?

Re: Missing bin suffix at getCodeSource().getLocation() [message #654612 is a reply to message #654566] Wed, 16 February 2011 13:41 Go to previous messageGo to next message
tomas  is currently offline tomas Friend
Messages: 3
Registered: February 2011
Junior Member
thanks for information
Re: Missing bin suffix at getCodeSource().getLocation() [message #654642 is a reply to message #654566] Wed, 16 February 2011 14:50 Go to previous messageGo to next message
Thomas Pilarski is currently offline Thomas PilarskiFriend
Messages: 6
Registered: November 2010
Location: Hannover
Junior Member
I have tried to create two ClassFinder projects - one for standalone application and the other for the eclipse plug-in project. I am using

Bundle bundle = FrameworkUtil.getBundle(containedClass);

try {
URL url = bundle.getEntry(packageName.replace('.', '/'));
uri = FileLocator.toFileURL(url).toURI();
}

and it still does not work.
I have to add the "bin/" prefix myself.

URL url = bundle.getEntry("bin/" + packageName.replace('.', '/'));

It is a bug or did I misunderstand the usage of the getEntry method?
Re: Missing bin suffix at getCodeSource().getLocation() [message #654715 is a reply to message #654642] Wed, 16 February 2011 19:20 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/16/2011 09:50 AM, Thomas Pilarski wrote:
>
> It is a bug or did I misunderstand the usage of the getEntry method?

getEntry is about finding bundle resources that will be available in
your plugin (i.e. you have a <project>/icons directory to be included in
your plugin).

It apparently doesn't work against source or java resources.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Missing bin suffix at getCodeSource().getLocation() [message #654716 is a reply to message #654566] Wed, 16 February 2011 19:28 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/16/2011 05:43 AM, Thomas Pilarski wrote:
> I don't understand the apply. The AModelEditor uses the ATransformation
> plugin to transform the edited model. I am using
> aClassLoader.getResources(package.replace('.', '/')) and directory
> search to find the classes.

It's this search that you can't do reliably.

In java (in general) there's no reliable way to get a list of all of the
classes supplied in 1) the classpath or 2) even for a specific package.
Changes to the environment (from a java app to an applet to a
container environment) change how classes are looked up.

In just java, if the problem is you need a set of classes to "publish"
themselves to your STI jar so they can be used for transforms, you can
have the ATransformation jar include some kind of txt file, a properties
file that STI can be handed, so it can load the classes. You could also
use Service Provider Interface between STI and ATransformations. That's
allows ATransformations to publish classes in both java and would work
within eclipse.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Missing bin suffix at getCodeSource().getLocation() [message #654790 is a reply to message #654716] Thu, 17 February 2011 07:54 Go to previous message
Thomas Pilarski is currently offline Thomas PilarskiFriend
Messages: 6
Registered: November 2010
Location: Hannover
Junior Member
Thank you for your help. I will use a special class loader for developing purposes and replace it, by a class list file, when it's ready.
Previous Topic:LTK: No default action starting Apply Script wizard?
Next Topic:Accessing PUTTY from Eclipse 3.3
Goto Forum:
  


Current Time: Thu Mar 28 14:46:38 GMT 2024

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

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

Back to the top