External Jar needed in the plugin

42 views
Skip to first unread message

fernando

unread,
May 17, 2012, 3:46:54 PM5/17/12
to cytoscape-discuss
Hi,

I need to copy 3 external .jar to the plugin cytoscape folder in order
to perform correctly my plugin. I have read in the foro a lot of
entries with this topic but really any has been useful totally.

I know i can use something like this:
File f = new File(this.getClass().getResource("jxl.jar").toURI());

and after move the file to the plugin folder, but java does not find
jxl.jar (is the .jar inside of my_plugin.jar) so i can not move any
jar.


Any Idea.
I guess this issue has to be very common.

Is the last step in the plugin. I would like finish :)

Thank you in advance

Jason Montojo

unread,
May 17, 2012, 4:40:15 PM5/17/12
to cytoscap...@googlegroups.com
Hi Fernando,

Class.getResource() only works on things that are in the ClassLoader's classpath.  The ClassLoader that's used to load your plugin only includes your plugin's JAR file in its classpath.  That means other JARs in the plugin folder won't be visible to your plugin through getResource().

If your plugin depends on external JARs, you need to unpack those JARs and package them inside your JAR.  So if you have a file foo.txt, you can use MyPlugin.class.getResource("/foo.txt") to access it.  The leading "/" is important because it tells Java not to use MyPlugin's package name when trying to resolve the location of foo.txt.

Is there a particular reason you're trying to get the JAR file's URI?  Or is your end goal to get some resource within the JAR file?

Hope this helps,
Jason


--
You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
To post to this group, send email to cytoscap...@googlegroups.com.
To unsubscribe from this group, send email to cytoscape-disc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.


lionel....@free.fr

unread,
May 17, 2012, 5:29:47 PM5/17/12
to cytoscap...@googlegroups.com
Hello Fernando,

an other solution is to build your jar including the external jar classes and resources automatically. To do so, it is possible to include a specific command in your ant build task (if you use ant) to ask it to automaticaly get the files of the external jar and include them into your plugin jar. The line to add in the jar target of the ant build task is something like: <zipgroupfileset dir="lib" includes="**/*.jar"/> (I would be able to bring you a more precise example when I will get back to my code next monday).
Note that if the external jar contains specific signature it must be removed from its manifest file before.

cheers

Lionel

----- Mail original -----
De: "Jason Montojo" <jrr...@gmail.com>
À: cytoscap...@googlegroups.com
Envoyé: Jeudi 17 Mai 2012 22:40:15
Objet: Re: [Cytoscape-discuss] External Jar needed in the plugin

fernando

unread,
May 18, 2012, 2:30:30 PM5/18/12
to cytoscape-discuss
Thanks Jason and Lionel,

I finally unajar my external libs and i include them into my jar
like .class files. Maybe is not the nicest way but it works perfect
for me.

cheers

On 17 mayo, 23:29, lionel.spine...@free.fr wrote:
> Hello Fernando,
>
> an other solution is to build your jar including the external jar classes and resources automatically. To do so, it is possible to include a specific command in your ant build task (if you use ant) to ask it to automaticaly get the files of the external jar and include them into your plugin jar. The line to add in the jar target of the ant build task is something like:  <zipgroupfileset dir="lib" includes="**/*.jar"/> (I would be able to bring you a more precise example when I will get back to my code next monday).
> Note that if the external jar contains specific signature it must be removed from its manifest file before.
>
> cheers
>
> Lionel
>
> ----- Mail original -----
> De: "Jason Montojo" <jrr...@gmail.com>
> À: cytoscap...@googlegroups.com
> Envoyé: Jeudi 17 Mai 2012 22:40:15
> Objet: Re: [Cytoscape-discuss] External Jar needed in the plugin
>
> Hi Fernando,
>
> Class.getResource() only works on things that are in the ClassLoader's classpath. The ClassLoader that's used to load your plugin only includes your plugin's JAR file in its classpath. That means other JARs in the plugin folder won't be visible to your plugin through getResource().
>
> If your plugin depends on external JARs, you need to unpack those JARs and package them inside your JAR. So if you have a file foo.txt, you can use MyPlugin.class.getResource("/foo.txt") to access it. The leading "/" is important because it tells Java not to use MyPlugin's package name when trying to resolve the location of foo.txt.
>
> Is there a particular reason you're trying to get the JAR file's URI? Or is your end goal to get some resource within the JAR file?
>
> Hope this helps,
> Jason
>
Reply all
Reply to author
Forward
0 new messages