Download

Online

Gallery

Blog

  Index  | Recent Threads  | List Attachments  | Search
 Welcome Guest  |  Register  |  Login
Login Name  Password
 

Sweet Home 3D Forum



No member browsing this thread
Thread Status: Active
Total posts in this thread: 5
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 5646 times and has 4 replies Next Thread
clanmills
Member
Member's Avatar

England
Joined: May 16, 2014
Post Count: 33
Status: Offline
Reply to this Post  Reply with Quote 
How to load "foreign" jars from a Plugin?

Folks

I've written a Plugin that uses 3 other jars.

-rw-r--r--@ 1 rmills staff 23K 21 Jan 13:52 json-simple-1.1.1.jar
-rw-r--r--@ 1 rmills staff 23K 15 Jan 11:44 simple.jar
-rw-r--r--+ 1 rmills staff 312K 28 May 2014 ST-4.0.8.jar

When I execute SH3D on Eclipse, everything is working OK (Mac/Windows/Linux).

However, I'm wondering how to deploy this on a user's computer. On the Mac, I've added <string>path-to-jar</string> to <SH3D>.app/Contents/Resources/Info.plist in <key>ClassPath</key><array>...</array> On Linux, I've modified the -classpath argument in the script SweetHome3D. I've given up on Windows, although it's working from Eclipse. Of course, I don't expect users to modify those files. I've done that to debug my code.

The question is: Is there a directory into which jars should be added for use by plugins?

I've looked at the APIs in Java and I believe URLClassLoader will solve this issue. Before I hurt my head getting that to work, I wondered if there's something already in SW3D to handle this.
[Mar 2, 2015, 5:07:10 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to load "foreign" jars from a Plugin?

Did you try to put all the classes of the jars you need in the plug-in file it self?
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[Mar 2, 2015, 7:43:28 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
clanmills
Member
Member's Avatar

England
Joined: May 16, 2014
Post Count: 33
Status: Offline
Reply to this Post  Reply with Quote 
biggrin Re: How to load "foreign" jars from a Plugin?

Thanks, Emmanuel. I can't persuade Eclipse to do that.

I've tried unzipping the jar and adding it that way. Then I get compilation errors. However, that can't work because the tree of dependencies could be vast. And we don't want duplicate code loaded. I'm not sure jars should be in a jar. If another Plugin happened to use the same jar, you'd want the JVM to share. So, I think we have to tell the JVM - "load it from here".

The Plugin loads and executes (updates the UI). The moment the Plugin wants to use anything from the jars, it throws ClassDefNotFound. It feels to me that I have to modify the CLASSPATH and then he'd find the libraries. However, I think CLASSPATH is only used when java starts to initialise the ClassLoader.

I've tried other ideas such as putting the jars in the plugins directory and into the SW3D directories.

Tomorrow's another day. This isn't difficult, however it is mysterious! I'm going to the dentist tomorrow. That'll be more fun.
[Mar 2, 2015, 8:33:44 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to load "foreign" jars from a Plugin?

I would do it first "by hand" with a zip utility, i.e. once you compiled the classes of your plug-in and generated a jar file from them with Eclipse, open the jar file with a zip utility and add to it the content of json-simple-1.1.1.jar, simple.jar and ST-4.0.8.jar.
I've already done that in the past for some plug-ins, to include SunFlow classes or even JMF library.
Once it works, I think it should be time to learn Ant basics to automate compilation and plug-in generation. Ant is some kind of make but much simpler and nevertheless powerful. All Sweet Home 3D files I release are generated with Ant that you can even launch from Eclipse. With 1189 lines, the Ant build.xml file of Sweet Home 3D is probably not the easiest way to understand how Ant works, but compiling, creating a jar file and merging jar files is something you can do in just a few lines.

we don't want duplicate code loaded. I'm not sure jars should be in a jar.
You should include classes only in the final jar. Including jars would require a special class loader to extract them and it's a needless tedious task.
If another Plugin happened to use the same jar, you'd want the JVM to share.
The jar files you want to include are small and you shouldn't worry about that.

Hope you can make it...
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[Mar 3, 2015, 10:18:09 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
clanmills
Member
Member's Avatar

England
Joined: May 16, 2014
Post Count: 33
Status: Offline
Reply to this Post  Reply with Quote 
applause Re: How to load "foreign" jars from a Plugin?

Emmanuel

You are 100% correct. A big round of applause for M Puybaret.

When I merge the jars, everything works. I've added a script 'build' to the plugins directory. I'll figure the Ant/Eclipse/export later.

885 rmills@rmillsmbp:~/Library/Application Support/eTeks/Sweet Home 3D/plugins $ dir
-rw-r--r--+ 1 rmills staff 131K 3 Mar 13:49 ToWebPlugin.jar
-rwxr-xr-x@ 1 rmills staff 348B 3 Mar 13:48 build*
-rw-r--r--+ 1 rmills staff 312K 2 Mar 13:28 ST-4.0.8.jar
-rw-r--r--@ 1 rmills staff 23K 2 Mar 13:28 json-simple-1.1.1.jar
886 rmills@rmillsmbp:~/Library/Application Support/eTeks/Sweet Home 3D/plugins $ ./build
-rw-r--r--+ 1 rmills staff 133765 3 Mar 13:49 ToWebPlugin.jar
-rw-r--r--+ 1 rmills staff 399906 3 Mar 13:50 ToWebPlugin.jar
887 rmills@rmillsmbp:~/Library/Application Support/eTeks/Sweet Home 3D/plugins $

#!/bin/bash

##
# build ToWebPlugin.jar
##

# static data
foo=foo
jar=ToWebPlugin.jar

if [ -e "$jar" ]; then
ls -alt "$jar"
rm -rf "$foo"
mkdir "$foo"
for i in *.jar ; do (
cd "$foo"
jar xf ../$i
) done
cd $foo
jar cf "../$jar" *
cd ..
rm -rf "$foo"
ls -alt "$jar"
else
echo "file $jar does not exist"
fi

# That's all Folks!
##

Thank You very much indeed for your help. Merci Beaucoup!
[Mar 3, 2015, 2:50:12 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread

    Get Sweet Home 3D at SourceForge.net. Fast, secure and Free Open Source software downloads
   
© Copyright 2006-2024 eTeks - All rights reserved