Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Integrating dynamic classpath with Webstart?  (Read 1843 times)
0 Members and 1 Guest are viewing this topic.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Posted 2008-05-18 22:53:48 »

Hey there everyone -

I've got a game I'm working on (the Best Game Evar 2, check my signature) that uses a dynamic classpath in order to add custom triggers to level files. Basically, each level file also has a .class file with it, and that class file is loaded in via the class loader when the level runs.

Because I'm trying to make the game available via Webstart, I need to create a resource folder where all custom user data goes. That's no problem, but the class loader can't find anything in the resource loader, even if I specify the path. How do I add a specific folder (System.getProperty("user.home") + ".bge2/LevelScripts/") into the classpath with Webstart? I'm not sure how to put user.home in the JNLP file, either.

Thankee.

See my work:
OTC Software
Online kevglass

JGO Kernel


Medals: 171
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2008-05-18 22:56:51 »

If the app is signed then you should probably use an isolated URLClassLoader to load the classes you're talking about. Then you can add whatever you need at runtime. Also if your app is signed you can use System.getProperty("user.home").

Kev

Offline cylab

JGO Ninja


Medals: 50



« Reply #2 - Posted 2008-05-19 00:59:10 »

Why do you need to load the class file dynamically? Can't you put all the classes in a jar on the webserver and simply use Class.forName("foo.bar.MyClass") to load them?

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online kevglass

JGO Kernel


Medals: 171
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2008-05-19 01:15:09 »

I'm guessing these are meant to be user provided classes acting as "scripts" for some sort of modding system?

Kev

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #4 - Posted 2008-05-19 03:46:56 »

I should have been more specific, as usual.  Cheesy

The game comes with a level editor. Using it, the player can type in custom Java code that is then compiled into a .class file. When the level is loaded, the class file is run constantly. The problem is that, after having created the JAR, I obviously can't add the .class files directly into it. Instead, I need them to be saved in the user's resource folder as a part of the new level. In order for the class loader to see it, however, it seems like the .class file needs to be in the classpath. I'm wondering how to specify that part of the resources folder as the classpath.

See my work:
OTC Software
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #5 - Posted 2008-05-19 06:54:00 »

I have a similar problem .
I have find a solution for a non webstart application. But it seems that the class loader for webstart application is not the same and it fails.
If you find a solution, let me know  Wink.
Online kevglass

JGO Kernel


Medals: 171
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2008-05-19 07:42:47 »

URLClassLoader really is your answer. Create one, add the URL to the file system location in which your .class files exists (or to a JAR). Use that class loader to instance your classes (with loadClass()).

Kev

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #7 - Posted 2008-05-19 10:04:20 »

Hmmm it seems that i need to add the path to the jar (my web start application) because the  classes are instance of one of my abstract class.
And System.getProperty("java.class.path") don't return it.
Offline cylab

JGO Ninja


Medals: 50



« Reply #8 - Posted 2008-05-19 12:24:04 »

Shouldn't be neccessary. The URLClassLoader asks the parent classloader (e.g. your app) for classes it can't load from the given jars.

Mathias - I Know What [you] Did Last Summer!
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #9 - Posted 2008-05-19 12:55:31 »

Shouldn't be neccessary. The URLClassLoader asks the parent classloader (e.g. your app) for classes it can't load from the given jars.

I didn't use it (i just find out myselft  Grin). I work fine.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
protected void loadPlugin() throws MalformedURLException
    {        
      File rep = new File(repPlugin);
      URL url = rep.toURI().toURL();
      URL[] urls = new URL[]{url};
           
      URLClassLoader loader = new URLClassLoader(urls,this.getClass().getClassLoader());
     
      plugins.removeAllElements();
     
      File fic[] = rep.listFiles();
      for(int i=0;i<fic.length;i++)
      {
        if (fic[i].getName().endsWith(".class"))
        {
          try
          {
            System.out.println("Loading class : "+fic[i].getAbsolutePath());
             
            String fileName = fic[i].getName();
            String className = fileName.substring(0,fileName.indexOf("."));
            Class fileClass = loader.loadClass(className);
            Object fileObject = fileClass.newInstance();
           
            if (fileObject instanceof Plugin)
            {
              Plugin plugin = (Plugin)fileObject;
              plugins.add(plugin);
            }
          }
          catch(Exception ex)
          {
            System.out.println(ex.toString());
          }
        }
      }
     
      pluginListModel.setPlugins(plugins);
    }


repPlugin : String of the fullpath to the plugin folder
Plugin : my abstract class for plugins
plugins : a JList of my plugin

the plugins classes are in the default package.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #10 - Posted 2008-05-19 17:05:37 »

Beautiful. Thanks for the help, everyone.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (40 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!