Home » Eclipse Projects » Eclipse Platform » Attach source jar to class jar by plugin code
Attach source jar to class jar by plugin code [message #156194] |
Thu, 13 November 2003 02:40  |
Eclipse User |
|
|
|
Originally posted by: ric.danskebank.dk
Hi
I am developing a plugin where I am managing
the java build classpath for a project. In this
way I can change the jar files the project is using.
In Eclipse when you select a jar file and open the
associated properties window you can manually attach
the java source (for debuging purposes). In my case
this is also a jar file.
My question is: how can I do this 'java source attachment'
programmically in my plugin?
/Rico
|
|
| | | | |
Re: Attach source jar to class jar by plugin code [message #156305 is a reply to message #156296] |
Thu, 13 November 2003 09:31   |
Eclipse User |
|
|
|
The first IPath should be the path to the source JAR file, the second IPath
should be the root path in the source JAR file where the source starts. I.e.
if your source JAR file's structure is:
src/com/my/package/X,java
src/com/my/package/other/Y.java
then the root path is 'src'.
Note this root path can be null if you want is to be autodetected (this
costs a little bit more).
So you should write:
pfr.attachSource(jarSrcFile.getFullPath(), null, null);
Jerome
"Rico Steenfeldt " <ric@danskebank.dk> wrote in message
news:bp00rm$tk$1@eclipse.org...
> I tried with this method, but it do not seem to work.
> What is missing?
>
> public void doAttachSourceIFile(IProject project,IFile jarFile,IFile
> jarSrcFile){
>
>
> IPackageFragmentRoot pfr =
> JavaCore.createJarPackageFragmentRootFrom(jarFile);
>
> try {
> pfr.attachSource(jarFile.getFullPath(),jarSrcFile.getFullPat h(),null);
> } catch (JavaModelException e) {
> System.out.println("doAttachSourceIFile: failed");
> }
>
> }
>
> Jerome Lanneluc wrote:
>
> > See IPackageFragmentRoot.attachSource(IPath, IPath, IProgressMonitor)
>
> > Jerome
>
> > "Rico Steenfeldt " <ric@danskebank.dk> wrote in message
> > news:bovf2i$cvm$1@eclipse.org...
> > >
> > > I forgot to mention that I need to attach source to both
> > > a jar file within the project workspace, and to a jar file
> > > outside the workspace (referenced by classpath variable).
> > >
> > >
> > >
> > > Rico Steenfeldt wrote:
> > >
> > > > Hi
> > >
> > > > I am developing a plugin where I am managing
> > > > the java build classpath for a project. In this
> > > > way I can change the jar files the project is using.
> > >
> > > > In Eclipse when you select a jar file and open the
> > > > associated properties window you can manually attach
> > > > the java source (for debuging purposes). In my case
> > > > this is also a jar file.
> > >
> > > > My question is: how can I do this 'java source attachment'
> > > > programmically in my plugin?
> > >
> > > > /Rico
> > >
> > >
>
>
|
|
|
Re: Attach source jar to class jar by plugin code [message #156676 is a reply to message #156305] |
Fri, 14 November 2003 05:19   |
Eclipse User |
|
|
|
Originally posted by: ric.danskebank.dk
Hi
Yes, I mixed up things with the attachSource method. When I have the jar
file and the source jar file in the project workspace then I can make it
work with the following code:
public void doAttachSource(IFile jarFile,IFile jarSrcFile){
try {
IPackageFragmentRoot pfr =
JavaCore.createJarPackageFragmentRootFrom(jarFile);
pfr.attachSource(jarSrcFile.getLocation(),new Path(""),null);
} catch (JavaModelException e1) {
...
} catch (Exception e2){
...
}
}
In my version of Eclipse (2.0.3 / wsad 5.0.1) I get a null pointer
exception
if I use null as the rootPath. However it works when creating a Path with
an empty string.
However, I have another problem. I also need to attach the source jar to
a jar file both placed outside the workspace. The jar file is included in
the projects java build path with a classpath variable (say X) and an
extension (say Y/file.jar).
Using either the full path to the jar file or the string (X/Y/file.jar)
I cannot successfully create the needed IFile object required to create the
IPackageFragmentRoot. How do I do this? I am a little bit stuck with this.
A final question. You can manually attach a source jar file to a jar file
through the properties window. If I do this by code instead, is there a
way to make this visible in the properties window? There seems to be
different
properties window for this when the jar file is placed local in the
project workspace and when it is referenced through a classpath variable.
/Rico
Jerome Lanneluc wrote:
> The first IPath should be the path to the source JAR file, the second IPath
> should be the root path in the source JAR file where the source starts. I.e.
> if your source JAR file's structure is:
> src/com/my/package/X,java
> src/com/my/package/other/Y.java
> then the root path is 'src'.
> Note this root path can be null if you want is to be autodetected (this
> costs a little bit more).
> So you should write:
> pfr.attachSource(jarSrcFile.getFullPath(), null, null);
> Jerome
> "Rico Steenfeldt " <ric@danskebank.dk> wrote in message
> news:bp00rm$tk$1@eclipse.org...
> > I tried with this method, but it do not seem to work.
> > What is missing?
> >
> > public void doAttachSourceIFile(IProject project,IFile jarFile,IFile
> > jarSrcFile){
> >
> >
> > IPackageFragmentRoot pfr =
> > JavaCore.createJarPackageFragmentRootFrom(jarFile);
> >
> > try {
> > pfr.attachSource(jarFile.getFullPath(),jarSrcFile.getFullPat h(),null);
> > } catch (JavaModelException e) {
> > System.out.println("doAttachSourceIFile: failed");
> > }
> >
> > }
> >
> > Jerome Lanneluc wrote:
> >
> > > See IPackageFragmentRoot.attachSource(IPath, IPath, IProgressMonitor)
> >
> > > Jerome
> >
> > > "Rico Steenfeldt " <ric@danskebank.dk> wrote in message
> > > news:bovf2i$cvm$1@eclipse.org...
> > > >
> > > > I forgot to mention that I need to attach source to both
> > > > a jar file within the project workspace, and to a jar file
> > > > outside the workspace (referenced by classpath variable).
> > > >
> > > >
> > > >
> > > > Rico Steenfeldt wrote:
> > > >
> > > > > Hi
> > > >
> > > > > I am developing a plugin where I am managing
> > > > > the java build classpath for a project. In this
> > > > > way I can change the jar files the project is using.
> > > >
> > > > > In Eclipse when you select a jar file and open the
> > > > > associated properties window you can manually attach
> > > > > the java source (for debuging purposes). In my case
> > > > > this is also a jar file.
> > > >
> > > > > My question is: how can I do this 'java source attachment'
> > > > > programmically in my plugin?
> > > >
> > > > > /Rico
> > > >
> > > >
> >
> >
|
|
| | | |
Re: Attach source jar to class jar by plugin code [message #157277 is a reply to message #156813] |
Sat, 15 November 2003 06:42   |
Eclipse User |
|
|
|
Originally posted by: ric.danskebank.dk
Jerome Lanneluc wrote:
Thanks, your comments helped a lot.
The last question I have is this:
If you select at jar file and through the view context menu open the
associated Properties window, you can select the "Java Source Attachment"
property. I am not sure if this is an Eclipse or WSAD feature though.
Nevertheless, here you manually can specify a source jar file to be
attached to. At a later time you can open the Properties window associated
the jar file resource and see what source jar file that is the current
attached source. I guess this value is stored as a persistent property.
However, if I attach the source by means of my own plugin as we have
discussed,
then this is not reflected by the Properties window. I suppose this is
because
the relevant persistent property has not been changed accordingly. Is
there a way for me to set this persistent property? I guess I just need to
get the qualified name for this property, but I don't know where to look.
> I'm not sure how you create the IPackageFragmentRoot handle. You should not
> use JavaCore.createJarPackageFragmentRootFrom(IFile) as an external JAR
> cannot be represented by an IFile. Instead you should use
> IJavaProject.getPackageFragmentRoot(String).
> Jerome
> "Rico Steenfeldt " <ric@danskebank.dk> wrote in message
> news:bp2lqj$qeo$1@eclipse.org...
> >
> > I still can't figure it out ...
> >
> > Assume you have a classpath variable defined like this
> >
> > MY_CLASSPATH_VARIABLE that is mapped to the path 'C:/a/b/c'
> >
> > and that the jar files are placed relative to this at
> > '/some_folder/classFile.jar'
> > and '/some_folder/sourceFile.jar'
> >
> > Sure you can define the IPath objects like this
> >
> > IPath jarPath = JavaCore.getResolvedVariablePath(new
> > Path("MY_CLASSPATH_VARIABLE"));
> > jarPath = jarVariablePath.append("/some_folder/classFile.jar");
> >
> > If you print this out with
> >
> > System.out.println(jarPath.toString());
> >
> > you get the string
> >
> > 'C:/a/b/c/some_folder/classFile.jar'
> >
> > In a similar way you can define the source jar IPath object
> >
> > IPath srcPath = JavaCore.getResolvedVariablePath(new
> > Path("MY_CLASSPATH_VARIABLE"));
> > srcVariablePath = srcVariablePath.append("/some_folder/sourceFile.jar");
> >
> > In order to attach source to the jar file I have to create the
> > IPackageFragmentRoot
> > object. It takes an IFile object associated the jar file as argument.
> >
> > My problem is to create the IPackageFragmentRoot object because when I
> > create
> > the IFile object based on the IPath object 'jarPath' it do not translate
> > into
> > a usefull IFile object.
> >
> > If I do like this
> >
> > IFile jarIFile = project.getFile(jarPath);
> >
> > and make a printout:
> >
> > System.out.println(jarIFile.getLocation().toString());
> >
> > I get something like this
> >
> > 'C:/my_runtime_workspace_path/my_project/a/b/c/some_folder/c lassFile.jar'
> >
> > that ofcourse do not exist, consequently I cannot create the
> > IPackageFragmentRoot object
> > on which I have to make the attachSource operation.
> >
> > Any ideas?
> >
> >
> >
> > Jerome Lanneluc wrote:
> >
> > > "Rico Steenfeldt " <ric@danskebank.dk> wrote in message
> > > news:bp2a73$d1r$1@eclipse.org...
> >
> > > > In my version of Eclipse (2.0.3 / wsad 5.0.1) I get a null pointer
> > > > exception if I use null as the rootPath.
> >
> > > That's expected. Since you didn't specify the version of Eclipse you
> were
> > > using, I assumed 3.0 M4 (last stable build).
> >
> > > > However it works when creating a Path with
> > > > an empty string.
> >
> > > Glad to hear this.
> >
> > > > However, I have another problem. I also need to attach the source jar
> to
> > > > a jar file both placed outside the workspace. The jar file is included
> in
> > > > the projects java build path with a classpath variable (say X) and an
> > > > extension (say Y/file.jar).
> > > > Using either the full path to the jar file or the string
> (X/Y/file.jar)
> > > > I cannot successfully create the needed IFile object required to
> create
> > > the
> > > > IPackageFragmentRoot. How do I do this? I am a little bit stuck with
> this.
> >
> > > You need to resolve the variable. See
> > > JavaCore.getResolvedVariablePath(IPath).
> >
> > > > A final question. You can manually attach a source jar file to a jar
> file
> > > > through the properties window. If I do this by code instead, is there
> a
> > > > way to make this visible in the properties window? There seems to be
> > > > different
> > > > properties window for this when the jar file is placed local in the
> > > > project workspace and when it is referenced through a classpath
> variable.
> >
> > > Not sure what you're talking about. I would have to go to Eclipse 2.0.3
> to
> > > see it. Or you can use WSAD 5.1 (based on Eclipse 2.1.1) and see if you
> > > still have the problem.
> >
> >
|
|
|
Re: Attach source jar to class jar by plugin code [message #157669 is a reply to message #157277] |
Mon, 17 November 2003 05:45  |
Eclipse User |
|
|
|
It sounds like a bug. Please enter a bug against JDT/Core.
Jerome
"Rico Steenfeldt " <ric@danskebank.dk> wrote in message
news:bp53ef$4q6$1@eclipse.org...
> Jerome Lanneluc wrote:
>
> Thanks, your comments helped a lot.
>
> The last question I have is this:
>
> If you select at jar file and through the view context menu open the
> associated Properties window, you can select the "Java Source Attachment"
> property. I am not sure if this is an Eclipse or WSAD feature though.
> Nevertheless, here you manually can specify a source jar file to be
> attached to. At a later time you can open the Properties window associated
> the jar file resource and see what source jar file that is the current
> attached source. I guess this value is stored as a persistent property.
>
> However, if I attach the source by means of my own plugin as we have
> discussed,
> then this is not reflected by the Properties window. I suppose this is
> because
> the relevant persistent property has not been changed accordingly. Is
> there a way for me to set this persistent property? I guess I just need to
> get the qualified name for this property, but I don't know where to look.
>
> > I'm not sure how you create the IPackageFragmentRoot handle. You should
not
> > use JavaCore.createJarPackageFragmentRootFrom(IFile) as an external JAR
> > cannot be represented by an IFile. Instead you should use
> > IJavaProject.getPackageFragmentRoot(String).
>
> > Jerome
>
> > "Rico Steenfeldt " <ric@danskebank.dk> wrote in message
> > news:bp2lqj$qeo$1@eclipse.org...
> > >
> > > I still can't figure it out ...
> > >
> > > Assume you have a classpath variable defined like this
> > >
> > > MY_CLASSPATH_VARIABLE that is mapped to the path 'C:/a/b/c'
> > >
> > > and that the jar files are placed relative to this at
> > > '/some_folder/classFile.jar'
> > > and '/some_folder/sourceFile.jar'
> > >
> > > Sure you can define the IPath objects like this
> > >
> > > IPath jarPath = JavaCore.getResolvedVariablePath(new
> > > Path("MY_CLASSPATH_VARIABLE"));
> > > jarPath = jarVariablePath.append("/some_folder/classFile.jar");
> > >
> > > If you print this out with
> > >
> > > System.out.println(jarPath.toString());
> > >
> > > you get the string
> > >
> > > 'C:/a/b/c/some_folder/classFile.jar'
> > >
> > > In a similar way you can define the source jar IPath object
> > >
> > > IPath srcPath = JavaCore.getResolvedVariablePath(new
> > > Path("MY_CLASSPATH_VARIABLE"));
> > > srcVariablePath =
srcVariablePath.append("/some_folder/sourceFile.jar");
> > >
> > > In order to attach source to the jar file I have to create the
> > > IPackageFragmentRoot
> > > object. It takes an IFile object associated the jar file as argument.
> > >
> > > My problem is to create the IPackageFragmentRoot object because when I
> > > create
> > > the IFile object based on the IPath object 'jarPath' it do not
translate
> > > into
> > > a usefull IFile object.
> > >
> > > If I do like this
> > >
> > > IFile jarIFile = project.getFile(jarPath);
> > >
> > > and make a printout:
> > >
> > > System.out.println(jarIFile.getLocation().toString());
> > >
> > > I get something like this
> > >
> > >
'C:/my_runtime_workspace_path/my_project/a/b/c/some_folder/c lassFile.jar'
> > >
> > > that ofcourse do not exist, consequently I cannot create the
> > > IPackageFragmentRoot object
> > > on which I have to make the attachSource operation.
> > >
> > > Any ideas?
> > >
> > >
> > >
> > > Jerome Lanneluc wrote:
> > >
> > > > "Rico Steenfeldt " <ric@danskebank.dk> wrote in message
> > > > news:bp2a73$d1r$1@eclipse.org...
> > >
> > > > > In my version of Eclipse (2.0.3 / wsad 5.0.1) I get a null pointer
> > > > > exception if I use null as the rootPath.
> > >
> > > > That's expected. Since you didn't specify the version of Eclipse you
> > were
> > > > using, I assumed 3.0 M4 (last stable build).
> > >
> > > > > However it works when creating a Path with
> > > > > an empty string.
> > >
> > > > Glad to hear this.
> > >
> > > > > However, I have another problem. I also need to attach the source
jar
> > to
> > > > > a jar file both placed outside the workspace. The jar file is
included
> > in
> > > > > the projects java build path with a classpath variable (say X) and
an
> > > > > extension (say Y/file.jar).
> > > > > Using either the full path to the jar file or the string
> > (X/Y/file.jar)
> > > > > I cannot successfully create the needed IFile object required to
> > create
> > > > the
> > > > > IPackageFragmentRoot. How do I do this? I am a little bit stuck
with
> > this.
> > >
> > > > You need to resolve the variable. See
> > > > JavaCore.getResolvedVariablePath(IPath).
> > >
> > > > > A final question. You can manually attach a source jar file to a
jar
> > file
> > > > > through the properties window. If I do this by code instead, is
there
> > a
> > > > > way to make this visible in the properties window? There seems to
be
> > > > > different
> > > > > properties window for this when the jar file is placed local in
the
> > > > > project workspace and when it is referenced through a classpath
> > variable.
> > >
> > > > Not sure what you're talking about. I would have to go to Eclipse
2.0.3
> > to
> > > > see it. Or you can use WSAD 5.1 (based on Eclipse 2.1.1) and see if
you
> > > > still have the problem.
> > >
> > >
>
>
|
|
|
Goto Forum:
Current Time: Sat May 03 08:54:34 EDT 2025
Powered by FUDForum. Page generated in 0.03765 seconds
|