Support classpath for AssetConfigURL

If URL constructor is used to access AssetConfigURL, we can’t use classpath to get it.



[patch]

Index: src/core/com/jme3/app/Application.java

===================================================================

— src/core/com/jme3/app/Application.java (revision 6297)

+++ src/core/com/jme3/app/Application.java (working copy)

@@ -120,16 +120,14 @@

private void initAssetManager(){

if (settings != null){

String assetCfg = settings.getString(“AssetConfigURL”);

  •        try {<br />
    

if (assetCfg != null){

  •                URL url = new URL(assetCfg);<br />
    
  •                URL url = Application.class.getResource(assetCfg);<br />
    
  •                if (url == null) {<br />
    
  •                    logger.log(Level.SEVERE, &quot;Unable to access URL in asset config:&quot; +assetCfg);<br />
    
  •                    return;<br />
    
  •                }<br />
    

assetManager = JmeSystem.newAssetManager(url);

}

  •        } catch (MalformedURLException ex) {<br />
    
  •            logger.log(Level.SEVERE, &quot;Unable to parse URL in asset config:&quot;<br />
    
  •                    +assetCfg, ex);<br />
    
  •            return;<br />
    
  •        }<br />
    

}

if (assetManager == null){

assetManager = JmeSystem.newAssetManager(



[/patch]

2 Likes

committed thanks

@Mulova: What’s the problem with doing App.class.getResource(…).toString() then setting that as the AssetConfigURL?

@Momoko_Fan In case of my project, I use custom class loader and packaging format to give it more security.

The config file is compressed into one file so I thought the resources can’t be represented not by URL but only by classpath.

But I was wrong. I tested and got the URL from what you said. :o

Thank you for the tip and sorry for the useless post. :smiley:

Now I have found a reason for this.

AFAIK, there is no standard classpath URL protocol such as ‘classpath:’

If AssetConfigURL can’t be represented as classpath, it will be changed according to the project path.

ok i’m gonna revert the change

@nehon Then, we can’t use classpath at AssetConfigURL

erf maybe I misunderstood, I stoped reading at

mulova said:
But I was wrong. I tested and got the URL from what you said. :o
Thank you for the tip and sorry for the useless post. :D

and didn't see the following post.
Sorry

@Momoko_Fan so what do we do? do I need to revert the reversion of the change :p

I had a specific usage in mind for this particular property …

What I wanted was to use a specific asset config file for applets/webstart that would specify some zip files on the website for use in loading assets. This allows you to package the same application as a desktop app and an applet by specifying that property and take advantage of dynamic loading.

To summarize dynamic loading: if your applet is 100 MB you probably don’t want to download it all at once when the user goes to the applet, you want to download just the code and then dynamically get whatever assets are needed.



So anyway, we might want to have separate properties for “AssetConfigURL” and maybe “AssetConfigResource” or something, I don’t know

Then, let’s get URL using constructor and when it fails use Class.getResource().

Does this solve what your are concerned about?

[patch]

Index: src/core/com/jme3/app/Application.java

===================================================================

— src/core/com/jme3/app/Application.java (revision 6346)

+++ src/core/com/jme3/app/Application.java (working copy)

@@ -120,15 +120,21 @@

private void initAssetManager(){

if (settings != null){

String assetCfg = settings.getString(“AssetConfigURL”);

  •        try {<br />
    
  •            if (assetCfg != null){<br />
    
  •                URL url = new URL(assetCfg);<br />
    
  •                assetManager = JmeSystem.newAssetManager(url);<br />
    
  •        if (assetCfg != null){<br />
    
  •            URL url = null;<br />
    
  •            try {<br />
    
  •                url = new URL(assetCfg);<br />
    
  •            } catch (MalformedURLException ex) {<br />
    

}

  •        } catch (MalformedURLException ex) {<br />
    
  •            logger.log(Level.SEVERE, &quot;Unable to parse URL in asset config:&quot;<br />
    
  •                    +assetCfg, ex);<br />
    
  •            return;<br />
    
  •            if (url == null) {<br />
    
  •                url = Application.class.getResource(assetCfg);<br />
    
  •                if (url == null) {<br />
    
  •                    logger.log(Level.SEVERE, &quot;Unable to access AssetConfigURL in asset config:&quot;<br />
    
  •                            +assetCfg);<br />
    
  •                    return;<br />
    
  •                }<br />
    
  •            }<br />
    
  •            assetManager = JmeSystem.newAssetManager(url);<br />
    

}

}

if (assetManager == null){

[/patch]

1 Like

Okay thanks, committed

As far as I understand it class.getResource() expects a relative URL. If you want to load an AssetConfig from somewhere else in the classpath, this may be confusing. This can be fixed by using class.getClassLoader().getResource() instead.



Suggested patch

[patch]Index: src/core/com/jme3/app/Application.java

===================================================================

— src/core/com/jme3/app/Application.java (revision 7849)

+++ src/core/com/jme3/app/Application.java (working copy)

@@ -157,7 +157,7 @@

} catch (MalformedURLException ex) {

}

if (url == null) {

  •                url = Application.class.getResource(assetCfg);<br />
    
  •                url = Application.class.getClassLoader().getResource(assetCfg);<br />
    

if (url == null) {

logger.log(Level.SEVERE, "Unable to access AssetConfigURL in asset config:{0}", assetCfg);

return;

[/patch]