SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-03-2010, 11:14 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Way to get a list of jars loaded into sage?

Header topic says it all it is late and I was just wondering short of calling a call and checking for an error.
Reply With Quote
  #2  
Old 01-03-2010, 11:58 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
As I understand it, JARs as such aren't loaded at all. JARs are just containers for class definitions, like zip files. When instantiating a class for the first time, Java searches the available JARs and loads the definition it finds. If you want to know what JAR files will be searched, look in the JARs directory.

I believe there are reflection methods in the Java runtime to find out what classes have been loaded into memory so far, but that doesn't tell the whole story about what classes are available to be instantiated.

What specific problem are you trying to solve?
__________________
-- Greg
Reply With Quote
  #3  
Old 01-04-2010, 05:53 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Specifically jars either not being in the jars folder or sage being restarted to load the new jars. Specifically right now your jar for use with my imports just thought it would be nice to get a list of classes loaded so if yours or mine or something else was missing I could provide a simple propmt on the ui side of things. I could search the directory I guess for the jars I want but that wouldn't really tell me if they were loaded or not (ie sage restarted)
Reply With Quote
  #4  
Old 01-04-2010, 06:45 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Plucky, I'm still a little unsure what it is that you are trying to do... do I'll go over a couple of approaches... First, as Greg noted, jars are not really loaded, just searched. There are ways to tell which loaded class belongs to which jar (if that what you are after).

If want to test if a class is loadable, you can use Class.forName("youclass") and catch a class not found exception if the class does not exist. For example if you wanted to test if the phoenix jar was available you could use Class.forName("phoenix.api") and it will throw a ClassNotFound exception if it does not exist.

But, if you are doing this all within java, to see if a user has your plugin installed correctly, then this code may never get triggered if it's inside one of your jars, that are not in the jars directory to begin with.

In bmt, i do some checks when it starts, where it looks for duplicate jars (by scanning the jar folder), and I log duplicates. From the commandline, I actually remove duplicates (only my jars).

Another approach is to check the versions of libraries that report a version. Phoenix contains an api phoenix.api.IsAtLeastVersion(Ver1, Ver2) that will return true if Ver1 is at least Ver2. ie, phoenix.api.IsAtLeastVersion(phoenix.api.GetVersion(), "1.44")

Hope this helps.
Reply With Quote
  #5  
Old 01-04-2010, 07:11 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Thanks sean the class check will probably be the easiest approach. It just all comes down to people not extracting the zips correctly and getting the jars in the right location so rather than troubleshoot them and find out they have not got the jars in the right place I was just going to create a quick check at the start of the stv for the jars needed.

Thanks for the advice

I sure wish there was a way to use new jars without a restart of sage service don't think it is possible but wanted to say
Reply With Quote
  #6  
Old 01-04-2010, 12:34 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
If you look at a debug log, about the second line from the top you'll see the classpath of JAR files that will be searched when trying to load a class. This classpath is built early during Sage startup by reading the contents of the JARs folder. Your problem is that a JAR dropped into that folder after Sage (or SageTVService) is already running won't be in that search path. That's what you're getting at when you talk about a JAR being "loaded" or not.

You can query the classpath yourself at runtime using java.lang.System.getProperty("java.class.path"). The result comes back as a giant semicolon-delimited string (like you see in the log file) that you can split into individual filenames or just search directly with String.contains(). That should tell you if a specific JAR was present in the JARs folder when Sage started.
__________________
-- Greg
Reply With Quote
  #7  
Old 01-04-2010, 02:53 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by PLUCKYHD View Post
I sure wish there was a way to use new jars without a restart of sage service don't think it is possible but wanted to say
Technically it is possible to dynamically load jars, but it would require some fundamental changes to the sage classloader. Frameworks, such as osgi, and webapps, provide a mechanism for loading and unloading "jars", but it's complicated, and it's not really "unloading"... so I won't get into that

Quote:
Originally Posted by GKusnick View Post
You can query the classpath yourself at runtime using java.lang.System.getProperty("java.class.path"). The result comes back as a giant semicolon-delimited string (like you see in the log file) that you can split into individual filenames or just search directly with String.contains(). That should tell you if a specific JAR was present in the JARs folder when Sage started.
Just a word of caution... it's actally not a semi-colon delimited list, but rather a path-separator delimited list, where the path-separator differs from windows to linux/mac. You can always get the current path separator using java.io.File.pathSeparator. This is important to realize when you are writing cross platform apps. (on windows it is a semi-colon, but on linux it's a colon)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
When Sage is loaded, volume on computer is locked???? though SageTV Software 2 03-17-2009 11:03 AM
STVI loaded twice..help...please garyellis SageTV Software 7 07-28-2006 04:53 PM


All times are GMT -6. The time now is 06:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.