Model embedded vs applet

167 views
Skip to first unread message

Maëlle Delay

unread,
Mar 25, 2013, 1:45:37 PM3/25/13
to netlog...@googlegroups.com
Hi,

I'm still trying to build my game with Netlogo and put it online. I didn't succeed using Hubnet but I can deal without, so let's try!

But I still have some issues to manage.

I want to pass variables from Java to my Netlogo game.

What is the best way between using an embedded model or an applet? Is there any compatibility issues with the embedded model?

In the case of the applet, I don't know how to pass parameters to the model. Do you have a way to do it?

Thanks!!

Maëlle

Maëlle Delay

unread,
Mar 25, 2013, 2:18:37 PM3/25/13
to netlog...@googlegroups.com
Humm I just realized that the embedded model opens in the server side and no in the client side...

So the only possibility to allow a player to play in its browser is to use applets?

Jason Bertsche

unread,
Mar 26, 2013, 12:06:47 PM3/26/13
to Maëlle Delay, netlog...@googlegroups.com
Hi Maëlle,

To better assist you, could you explain what you mean by "embedded model"?  Generally, I would think of applets as being embedded models, but it seems like that's not the case here.  Are you perhaps referring to Tortoise (https://github.com/NetLogo/NetLogo/wiki/Tortoise)?

Also, could you further explain what you're looking to do when you say "I want to pass variables from Java to my NetLogo game"?  At what point do you want the values to go into the game?—just when it starts, or throughout the run of the game?  Could this simply be handled by a NetLogo extension, or are these values coming from outside of NetLogo entirely?
Jason Bertsche
Software Developer - NetLogo
--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Maëlle Delay

unread,
Mar 27, 2013, 8:05:13 PM3/27/13
to Jason Bertsche, netlog...@googlegroups.com
Dear Jason,

For me the embedded model is the one you create using controlling codes like

import org.nlogo.lite.InterfaceComponent;
public class Example3 {
  public static void main(String[] argv) {
    try {
      final javax.swing.JFrame frame = new javax.swing.JFrame();
      final InterfaceComponent comp = new InterfaceComponent(frame);
      java.awt.EventQueue.invokeAndWait(
    new Runnable() {
      public void run() {
        frame.setSize(1000, 700);
        frame.add(comp);
        frame.setVisible(true);
        try {
          comp.open
          ("models/Sample Models/Earth Science/"
           + "Fire.nlogo");
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }}});

The applet is something else for me.

I want to pass or set a variable in Netlogo only when the model is setup. Basically only the name of the player which is come from my website session in Java. I need it to authentificate him in my database and I think that it is boring to ask him with user input (as he needs to login already to my website to play with the applet game).

I have also a more important issue with the applet. I use the sql extension and it can't be open anymore by the model. I got that sentence: Code: Can't open extension htttp://localhost:8080/Simulation/sql/sql.jar

The netlogo applet and model are in the Simulation folder with NetLogoLite and the NetLogoLite.jar.pack.gz. Do you know why it's not working?
It's still working fine with hubnet applet...

Thanks
2013/3/26 Jason Bertsche <jason.b...@northwestern.edu>

Seth Tisue

unread,
Mar 28, 2013, 9:40:44 AM3/28/13
to netlog...@googlegroups.com
>>>>> "Maëlle" == Maëlle Delay <delay....@gmail.com> writes:

Maëlle> I have also a more important issue with the applet. I use the
Maëlle> sql extension and it can't be open anymore by the model. I got
Maëlle> that sentence: Code: Can't open extension
Maëlle> htttp://localhost:8080/Simulation/sql/sql.jar

Maëlle> The netlogo applet and model are in the Simulation folder with
Maëlle> NetLogoLite and the NetLogoLite.jar.pack.gz. Do you know why
Maëlle> it's not working?

Is only the SQL extension problematic? Or are you unable to get *any*
extension to work?

Some example applets that use extensions are here:
http://ccl.northwestern.edu/netlogo/5.0.4/applet/

Not every extension works in applets. You might ask the author of the
SQL extension if it offers applet support.

Maëlle> So the only possibility to allow a player to play in its
Maëlle> browser is to use applets?

Yes. Or, well...

There's also Java Web Start, but that isn't really "in the browser".

You could also build your own client from scratch, in JavaScript or
whatever, and have it talk to NetLogo running on the server. But you'd
be building all of that yourself; we don't have anything like that
(yet!) that you can just use.

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/

Jason Bertsche

unread,
Mar 28, 2013, 1:52:24 PM3/28/13
to Seth Tisue, netlog...@googlegroups.com
Ahh.  Now that I see what you mean by "embedded model", I can better answer your question about whether or not applets are the only way to accomplish this.  So: They certainly are not, but, if you want to interact through the Controlling API with a NetLogo model running headless on a server—or (using your terminology) to interact with an embedded model—you'll need to build your own HTML/JavaScript front-end for sending messages to the server, and then program the server to correctly interpret/forward the messages to the headless NetLogo instance.  Applets—as gross as they are—are probably the easier solution.

The error message that you supplied regarding the SQL extension has three 't's in the "http" part of "htttp://localhost:8080/Simulation/sql/sql.jar".  Could that be the culprit, or was that just a typo?  If it was just a typo, I'm not sure what to make of that error.  The '.jar' is accessible at that location through the browser, right?

As Seth suggests, Java WebStart might be an option.  It's kind of like using applets, in that it allows you to launch NetLogo through the browser, but it doesn't actually run NetLogo in the browser; it's more so a seamless way of distributing NetLogo to other people's computers.  I wrote Reuven a lengthy piece about my Java WebStart JNLP generator here: https://groups.google.com/forum/?fromgroups=#!topic/netlogo-devel/xjqdEaVPadU .  In that post, I talk about how to send to my JNLP generator a configuration message that will be able to propagate a value down into NetLogo through Java system properties, and you can then read the properties in the model through the Props extension (https://github.com/NetLogo/Props-Extension).

However, since you're using the SQL extension—well, two things are likely to go wrong there.  First, I don't bundle that extension for distribution through the official SimServer instances, and I'm not really a fan of changing the official extension bundle to accommodate for a third-party project.  Secondly, it doesn't sound like WebStart is even something you want, because I would suspect that the SQL extension is accessing a database on the server that's hosting the NetLogo model.  That is, my suspicion is that there is only one database you are modifying, and not one database for each user of your model.  If that's true, having your model use the SQL extension from Web Start seems undesirable.  It's still possible that you could run the model through WebStart and use the Web extension (which is bundled with the other extensions on my official SimServer instances, https://github.com/NetLogo/Web-Extension) to remotely query your web server and tell it to make the SQL queries to a local database on the user's behalf, but this is now getting farther and farther from what your original plans....

One thing to perhaps look into is LiveConnect (http://jdk6.java.net/plugin2/liveconnect/, https://developer.mozilla.org/en-US/docs/LiveConnect), which allows Java applets and JavaScript to talk to one another.  You could conceivably grab the player's username in JavaScript and then call a method in the Java applet to pass the value in.  Or you could have the Java applet execute some JavaScript to get the username.  Either way, though, I think you'd have to modify 'NetLogo.jar' a bit.

The last option—probably the best, IMO—is that you can actually pass parameters directly applets when the applet loads—very similar to how I suggested with WebStart.  You can do so with a `param` tag (http://stackoverflow.com/questions/4130709/how-to-pass-system-properties-to-java-applet-launched-from-html)—note that the argument's key/name has to start with "-D" in order to be recognized as a system property!  I might suggest doing something similar to the top answer given in that StackOverflow question, and dynamically filling in the value of the system property when the web page is rendered.  Then, you can use the Props extension—easily buildable from source, or, if you run into troubles building it, I wouldn't mind just sending you a copy of 'props.jar', myself—to read the properties into the NetLogo model.

Jason Bertsche
Software Developer - NetLogo

Maëlle Delay

unread,
Mar 28, 2013, 4:40:39 PM3/28/13
to Jason Bertsche, Seth Tisue, netlog...@googlegroups.com
Thank you very much for your explanation.

I just quickly try with other extensions and I got an error only with the sql extension. So yes I assume that it's a problem with this extension.
I just let an issue on their forum. I hope somebody will answer. http://code.google.com/p/netlogo-sql/issues/detail?id=16

Yes I need to save every actions of the player on a database. One database for all the players.

Of course my favourite option if it's possible will be to pass variable with param tag in the applet and use the Props extension. I will try to build the jar. Last time I tried to compile a jar it was really not a success as I use Windows but maybe I will be luckier.

2013/3/28 Jason Bertsche <jason.b...@northwestern.edu>

Maëlle Delay

unread,
May 25, 2013, 7:35:34 PM5/25/13
to Jason Bertsche, Seth Tisue, netlog...@googlegroups.com
I'm back again on this issue. I don't succeed to build the props.jar
I'm using Netlogo 5.0.2. Is it possible to have help or the .jar?

For the sql extension, I resolve the issue. You need to create the sql.jar.pack.gz in order to use the sql extension within an applet.

2013/3/28 Maëlle Delay <delay....@gmail.com>

Jason Bertsche

unread,
May 25, 2013, 7:42:35 PM5/25/13
to Maëlle Delay, netlogo-devel

I'm back again on this issue. I don't succeed to build the props.jar

Since the last post on this thread, a link has become available to download the Props extension directly.� The link can be found on our "Extensions" page (along with links to most other non-bundled, CCL-based extensions).


Jason Bertsche
Software Developer - NetLogo
On 5/25/2013 6:35 PM, Ma�lle Delay wrote:
I'm back again on this issue. I don't succeed to build the props.jar
I'm using Netlogo 5.0.2. Is it possible to have help or the .jar?

For the sql extension, I resolve the issue. You need to create the sql.jar.pack.gz in order to use the sql extension within an applet.

2013/3/28 Ma�lle Delay <delay....@gmail.com>
Thank you very much for your explanation.

I just quickly try with other extensions and I got an error only with the sql extension. So yes I assume that it's a problem with this extension.
I just let an issue on their forum. I hope somebody will answer. http://code.google.com/p/netlogo-sql/issues/detail?id=16

Yes I need to save every actions of the player on a database. One database for all the players.

Of course my favourite option if it's possible will be to pass variable with param tag in the applet and use the Props extension. I will try to build the jar. Last time I tried to compile a jar it was really not a success as I use Windows but maybe I will be luckier.


2013/3/28 Jason Bertsche <jason.b...@northwestern.edu>
Ahh.� Now that I see what you mean by "embedded model", I can better answer your question about whether or not applets are the only way to accomplish this.� So: They certainly are not, but, if you want to interact through the Controlling API with a NetLogo model running headless on a server�or (using your terminology) to interact with an embedded model�you'll need to build your own HTML/JavaScript front-end for sending messages to the server, and then program the server to correctly interpret/forward the messages to the headless NetLogo instance.� Applets�as gross as they are�are probably the easier solution.

The error message that you supplied regarding the SQL extension has three 't's in the "http" part of "htttp://localhost:8080/Simulation/sql/sql.jar".� Could that be the culprit, or was that just a typo?� If it was just a typo, I'm not sure what to make of that error.� The '.jar' is accessible at that location through the browser, right?

As Seth suggests, Java WebStart might be an option.� It's kind of like using applets, in that it allows you to launch NetLogo through the browser, but it doesn't actually run NetLogo in the browser; it's more so a seamless way of distributing NetLogo to other people's computers.� I wrote Reuven a lengthy piece about my Java WebStart JNLP generator here: https://groups.google.com/forum/?fromgroups=#!topic/netlogo-devel/xjqdEaVPadU .� In that post, I talk about how to send to my JNLP generator a configuration message that will be able to propagate a value down into NetLogo through Java system properties, and you can then read the properties in the model through the Props extension (https://github.com/NetLogo/Props-Extension).

However, since you're using the SQL extension�well, two things are likely to go wrong there.� First, I don't bundle that extension for distribution through the official SimServer instances, and I'm not really a fan of changing the official extension bundle to accommodate for a third-party project.� Secondly, it doesn't sound like WebStart is even something you want, because I would suspect that the SQL extension is accessing a database on the server that's hosting the NetLogo model.� That is, my suspicion is that there is only one database you are modifying, and not one database for each user of your model.� If that's true, having your model use the SQL extension from Web Start seems undesirable.� It's still possible that you could run the model through WebStart and use the Web extension (which is bundled with the other extensions on my official SimServer instances, https://github.com/NetLogo/Web-Extension) to remotely query your web server and tell it to make the SQL queries to a local database on the user's behalf, but this is now getting farther and farther from what your original plans....

One thing to perhaps look into is LiveConnect (http://jdk6.java.net/plugin2/liveconnect/, https://developer.mozilla.org/en-US/docs/LiveConnect), which allows Java applets and JavaScript to talk to one another.� You could conceivably grab the player's username in JavaScript and then call a method in the Java applet to pass the value in.� Or you could have the Java applet execute some JavaScript to get the username.� Either way, though, I think you'd have to modify 'NetLogo.jar' a bit.

The last option�probably the best, IMO�is that you can actually pass parameters directly applets when the applet loads�very similar to how I suggested with WebStart.� You can do so with a `param` tag (http://stackoverflow.com/questions/4130709/how-to-pass-system-properties-to-java-applet-launched-from-html)�note that the argument's key/name has to start with "-D" in order to be recognized as a system property!� I might suggest doing something similar to the top answer given in that StackOverflow question, and dynamically filling in the value of the system property when the web page is rendered.� Then, you can use the Props extension�easily buildable from source, or, if you run into troubles building it, I wouldn't mind just sending you a copy of 'props.jar', myself�to read the properties into the NetLogo model.

Jason Bertsche
Software Developer - NetLogo
On 03/28/2013 08:40 AM, Seth Tisue wrote:
"Ma�lle" == Ma�lle Delay <delay....@gmail.com> writes:
 Ma�lle> I have also a more important issue with the applet. I use the
 Ma�lle> sql extension and it can't be open anymore by the model. I got
 Ma�lle> that sentence: Code: Can't open extension
 Ma�lle> htttp://localhost:8080/Simulation/sql/sql.jar

 Ma�lle> The netlogo applet and model are in the Simulation folder with
 Ma�lle> NetLogoLite and the NetLogoLite.jar.pack.gz. Do you know why
 Ma�lle> it's not working?

Is only the SQL extension problematic?  Or are you unable to get *any*
extension to work?

Some example applets that use extensions are here:
http://ccl.northwestern.edu/netlogo/5.0.4/applet/

Not every extension works in applets.  You might ask the author of the
SQL extension if it offers applet support.

 Ma�lle> So the only possibility to allow a player to play in its
 Ma�lle> browser is to use applets?

Yes.  Or, well...

There's also Java Web Start, but that isn't really "in the browser".

You could also build your own client from scratch, in JavaScript or
whatever, and have it talk to NetLogo running on the server.  But you'd
be building all of that yourself; we don't have anything like that
(yet!)  that you can just use.

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/


--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
�
�



Seth Tisue

unread,
May 25, 2013, 11:14:18 PM5/25/13
to netlogo-devel
>>>>> "Jason" == Jason Bertsche <jason.b...@northwestern.edu> writes:

>> I'm back again on this issue. I don't succeed to build the props.jar

Jason> Since the last post on this thread, a link has become available
Jason> to download the Props extension directly. The link can be found
Jason> on our "Extensions" page
Jason> <https://github.com/NetLogo/NetLogo/wiki/Extensions#other-ccl-extensions>
Jason> (along with links to most other non-bundled, CCL-based
Jason> extensions).

But the download only has a .jar -- it won't work in an applet without a
props.jar.pack.gz, too.

--
Seth Tisue | http://tisue.net

Seth Tisue

unread,
May 25, 2013, 11:15:39 PM5/25/13
to netlog...@googlegroups.com
>>>>> "Maëlle" == Maëlle Delay <delay....@gmail.com> writes:

Maëlle> I'm back again on this issue. I don't succeed to build the
Maëlle> props.jar

What exactly did you try and what error message did you get? Can you
show us a transcript of the build attempt?

Seth Tisue

unread,
May 25, 2013, 11:18:56 PM5/25/13
to netlogo-devel
>>>>> "Seth" == Seth Tisue <se...@tisue.net> writes:

>>>>> "Jason" == Jason Bertsche <jason.b...@northwestern.edu> writes:
>>> I'm back again on this issue. I don't succeed to build the
>>> props.jar

Jason> Since the last post on this thread, a link has become available
Jason> to download the Props extension directly. The link can be found
Jason> on our "Extensions" page
Jason> <https://github.com/NetLogo/NetLogo/wiki/Extensions#other-ccl-extensions>
Jason> (along with links to most other non-bundled, CCL-based
Jason> extensions).

Seth> But the download only has a .jar -- it won't work in an applet
Seth> without a props.jar.pack.gz, too.

Oh, but, wait... I realized after sending this, are unsigned Java
applets in general (not just NetLogo applets in particular) even allowed
by the security manager to read system properties at all? You might
double check it, but I don't think they are. And that would mean the
props extension would be useless in applets anyway.

Maëlle Delay

unread,
May 26, 2013, 6:33:50 AM5/26/13
to Seth Tisue, netlogo-devel
Thanks for the help. I have created the props.jar.pack.gz. But yes when I try to use it, I get an error access exception. I enclosed the error message (propserror.jpg)

With the extension sql, I have another behavior. It seems that the first time I try to launch the applet I get an runtime error message (sqlerror-part1 & 2 .jpg). The applet is displayed, buttons and view. But when I click on a button, nothing happens.
If I close the error message and relaunch the applet, I then can interact with the applet. Click on the button launch the associated function for example.
But when I want to query my database I get a runtime error: extension exception: No active database connection available
error while observer running SQL:EXEC_QUERY

2013/5/26 Seth Tisue <se...@tisue.net>
propserror.jpg
sqlerror-part1.jpg
sqlerror-part2.jpg

Seth Tisue

unread,
May 26, 2013, 9:19:03 AM5/26/13
to netlogo-devel
>>>>> "Maëlle" == Maëlle Delay <delay....@gmail.com> writes:

Maëlle> With the extension sql, I have another behavior. It seems that
Maëlle> the first time I try to launch the applet I get an runtime
Maëlle> error message (sqlerror-part1 & 2 .jpg). The applet is
Maëlle> displayed, buttons and view. But when I click on a button,
Maëlle> nothing happens. If I close the error message and relaunch the
Maëlle> applet, I then can interact with the applet. Click on the
Maëlle> button launch the associated function for example. But when I
Maëlle> want to query my database I get a runtime error: extension
Maëlle> exception: No active database connection available error while
Maëlle> observer running SQL:EXEC_QUERY

This could be something you'd need to take up with the author of that
extension. But offhand, it sounds like it could be another applet
security restriction problem. Unsigned applets are only allowed to
contact the server that the applet itself was served from; perhaps your
database server is some other server...?

Jason Bertsche

unread,
May 27, 2013, 12:43:49 AM5/27/13
to Seth Tisue, netlogo-devel ë
But the download only has a .jar -- it won't work in an applet without a props.jar.pack.gz, too.

That's not true.  If the '.jar.pack.gz' isn't found, the launcher looks for the plain '.jar'.  The '.jar.pack.gz' just makes the download smaller (if it's available).


Oh, but, wait... I realized after sending this, are unsigned Java
applets in general (not just NetLogo applets in particular) even allowed
by the security manager to read system properties at all?

Oh, applets....  *sigh*  Why, why, why....

Yes, you're right.  It hadn't occurred to me that reading/writing the VM's system properties should require elevated privileges—still doesn't make a whole lot of sense to me, given that reading them is fairly harmless, and you can set them directly in the in HTML of the page with `-D<arg>=<value>` arguments, anyway!—but you are correct.

And [the security restrictions] would mean the props extension would be useless in applets anyway.

Useless: No

Kind of inconvenient to leverage: Yes

But when I want to query my database I get a runtime error: extension
exception: No active database connection available error while observer running SQL:EXEC_QUERY
[...] offhand, it sounds like it could be another applet security restriction problem.

From the tests that I've done on my machine, that seems to be the case.  It's curious to me that the exception doesn't display like other security access violations, but it failed for me just like how Maëlle described when the '.jar's weren't signed, and worked fine for me when they were signed, so... causality.

Alright, so... looks like you need some signed '.jar's, Maëlle.  This will require some more effort, but I've tested it out and verified that both the Props and SQL extensions seem to work without security access violations when the '.jar's are signed.

To get started, you'll first need a key with which to sign the '.jar's.  To create one, run `keytool -genkey -alias <your desired keyname; for the remainder on this monologue, this will be "coolkey">` from the command line and fill out the resulting questionnaire—a bit obnoxious, I know.  If your shell complains that 'keytool' is not found, ensure that the 'bin' folder of your JDK is on your path.  (Some additional info on 'keytool' here.)

Alright, we now have a key for signing '.jar's.  Now, we actually have to sign them.  (P.S. This part sucks....)  Except that I created a script that makes it bearable!  See, the 'jarsigner' utility is a real piece of crap, and it only works on one '.jar' at a time, and, on top of that, '.jar's are peculiar about the order in which they must be packed and signed, so... having a script to automate this esoteric little process really makes things nicer.

Here's my 'packer' script:

```
#!/bin/sh

for file in $1
do
  echo "Packing $file"
  pack200 -r $file
  jarsigner $file coolkey
  pack200 --modification-time=latest --effort=9 --no-keep-file-order $file.pack.gz $file
done
```

In a directory containing '.jar's that you want to sign, call it like this: `packer "*.jar"`.  You might ask why there need to be the quotes in there.  Honestly, I don't know, and I admit that this is a very novice script, and, I also admit that it would be nicer if the script remembered your passphrases and didn't ask you for them for each '.jar' being signed, but I'm actually not interested enough in shell scripts to improve that aspect of it....  *shrug*

Be sure to modify the script to change "coolkey" to whatever the name of your keystore from above was!

So... the '.jar's that need to get signed are... all of them.  If so much as a single '.jar' is loaded without being signed, your applet is going to fail—and they all need to be signed with the same signature, too!  So run that script on all of the '.jar's in both the Props and SQL extensions' folders, and on 'NetLogoLite.jar', too.  Also, you can/should throw out the old 'NetLogoLite.jar.pack.gz'; '.jar's need to be signed before they're compressed (and packed before they're signed (see earlier reference to esotericism)).

Okay, we should now have signed, packed '.jar's.  Now, we need to launch NetLogo with the elevated permissions that having these signed '.jar's allows us to have.  We can't do that with a simple `<applet>` HTML tag, though.  Well, I've sometimes read that you can use an `<applet>` tag and a custom-made Java '.policy' file, but I've yet to ever see that work.  Instead, I think we just need to use JNLP files.  Resources that I found useful when setting up my first JNLP-based applet the other night: one, another, yet another.  Regardless, I'll try to guide you through the process without you needing to bother with those resources.

So, basically, given your situation, you want to pass in dynamic data to the applet.  To do so, we're going to use Java system properties.  Java system properties are specified for a JNLP-based applet in the JNLP file.  As such, you're going to need a different JNLP file for each configuration, meaning that you'll need to dynamically create JNLP files, and then dynamically generate the HTML that directs the user towards the correct JNLP file.  I'll supply some template code for each of those in a bit.  But, since I have some experience with JNLP files for Java WebStart, I'll make a recommendation here: have a separate folder in your applet's directory just for JNLP files, and name each generated JNLP file as "<UUID>.jnlp", where "<UUID>", of course, is just some UUID that you generate when you go to create the file.

As such, I suggest a folder structure like this:

```
project_root
-<HTML file>
-<NetLogo model file>
-NetLogoLite.jar
-NetLogoLite.jar.pack.gz
-jnlp
--<all of your JNLP files>
-props
--<Props' '.jar's and '.jar.pack.gz's>
-sql
--<SQL's '.jar's and '.jar.pack.gz's>
-<folders for any/all other extensions that you need>
```

My HTML and JNLP templates will expect a directory structure like the one listed above.  If you go with a different structure, you may need to change the HTML/JNLP accordingly.

For the HTML, it's fairly simple; we just replace the old `<applet>` tag with some JavaScript that launches the JNLP as an applet:

```
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {code: 'components.MyApplet',  width: 675, height: 480} ;
    var parameters = {jnlp_href: 'jnlp/MyApplet.jnlp'} ;
    deployJava.runApplet(attributes, parameters, '1.6');
</script>
```

I don't think that the "MyApplet" in "components.MyApplet" means much of anything here, but, since I advised naming the JNLPs by UUID, you're going to want to replace "jnlp/MyApplet.jnlp" with "jnlp/<UUID>.jnlp".  And... that should be the only dynamic part of rendering the page's HTML.  If you don't put your JNLPs in some 'jnlp' folder, you'll want to change the "jnlp/" in "jnlp/MyApplet.jnlp" to properly reflect where your JNLPs are.

Now for generating the JNLP.  Here's the template:

```
<?xml version="1.0" encoding="UTF-8"?>
<jnlp href="MyApplet.jnlp">
    <information>
        <title>Props/SQL/Applet Example</title>
        <vendor>CCL</vendor>
    </information>
    <security> <all-permissions/> </security>
    <resources>

        <property name="jnlp.packEnabled" value="true"/>

        <!-- Dynamic data through Java system properties! -->
        <property name="netlogo.data" value="Secret data!"/>

        <!-- Application Resources -->
        <j2se version="1.6+" />
        <jar href="../NetLogoLite.jar" main="true" />
        <jar href="../props/props.jar"/>
        <jar href="../sql/sql.jar"/>
        <jar href="../sql/bonecp-0.7.0.jar"/>
        <jar href="../sql/guava-r07.jar"/>
        <jar href="../sql/mysql-connector-java-5.1.19.jar"/>
        <jar href="../sql/postgresql-9.1-901.jdbc4.jar"/>
        <jar href="../sql/slf4j-api-1.5.10.jar"/>
        <jar href="../sql/slf4j-simple-1.5.10.jar"/>

    </resources>
    <applet-desc
        name="Props/SQL Applet"
         main-class="org.nlogo.lite.Applet"
         width="675"
         height="480">
         <param name="DefaultModel" value="../MyApplet.nlogo"/>
    </applet-desc>
    <update check="background"/>
</jnlp>
```

Replace `jnlp \ information \ title`, `jnlp \ information \ vendor`, and `jnlp \ applet-desc.name` with values that are more representative of your situation.

`<security> <all-permissions/> </security>`: This is what launches the applet with elevated permissions, allowing the use of these extensions.

`<property name="netlogo.data" value="Secret data!"/>`: This makes it so that, if you were to call `props:get "netlogo.data"` within the NetLogo applet, you should get the value "Secret data!" back.  Change the property name as you see fit, and set the value dynamically at JNLP-generation time with the data you want to propagate into NetLogo (I probably don't need to tell you this, since this data is largely the whole point of everything I'm saying here).  Naturally, you can add virtually as many `<property />` tags as you'd like, to load in lots of different values.

`<jnlp href="MyApplet.jnlp">`: This is also something that needs to be set dynamically by you.  Since we don't specify a `codebase` attribute in this tag, the JNLP's "codebase" is inferred to be the folder in which the JNLP sits.  What is means is that other URLs are interpreted as being relative the location the JNLP.  Since I advised that JNLPs go in './jnlp', the '.jar' file paths and the model path should be preceded with "../" (as shown here).  If you go with a different directory structure, or if you manually set the `codebase` attribute, adjust the paths in the JNLP accordingly.  Also, make sure to change the "MyApplet.jnlp" in the `href` here to dynamically be "<UUID>.jnlp", so as to match the actual name of the file.  (Truth be told, I've never really understood the necessity of this aspect of JNLPs, given how redundant it is.)

And... that should do it.

I hope that helps....

Seth Tisue

unread,
May 27, 2013, 1:16:47 AM5/27/13
to netlog...@googlegroups.com
>>>>> "Jason" == Jason Bertsche <jason.b...@northwestern.edu> writes:

>> But the download only has a .jar -- it won't work in an applet
>> without a props.jar.pack.gz, too.

Jason> That's not true. If the '.jar.pack.gz' isn't found, the
Jason> launcher looks for the plain '.jar'.

One would think so, but our users have found that in practice, it
doesn't always work like that. See
https://github.com/NetLogo/NetLogo/issues/95 and
https://github.com/NetLogo/NetLogo/issues/117 .

I was imprecise when I said "it won't work". I meant "it won't
*necessarily* work".

Maëlle Delay

unread,
May 27, 2013, 4:00:28 AM5/27/13
to Jason Bertsche, netlog...@googlegroups.com
I can not find the words to thank you! I find again hope to succeed to run my game online.
I will try to follow all these steps and let you know if I succeed

Thank so much for your help and quick answers!!!

2013/5/27 Seth Tisue <se...@tisue.net>

Maëlle Delay

unread,
May 28, 2013, 12:48:57 PM5/28/13
to Jason Bertsche, netlog...@googlegroups.com
Ok so I succeed to run your applet, to connect to my database and read some data.
But I don't succeed to access to the netlogo.data.
When I use that code:
extensions [props]

to startup
  output-write props:get "netlogo.data"
end

I only get false in the output.
Only when I set from the code with props:set "netlogo.data" "value" I get value return...

Do I miss something? Is not enough to put the value in the jnlp file?
Thanks

2013/5/27 Maëlle Delay <delay....@gmail.com>

Jason Bertsche

unread,
May 29, 2013, 2:07:24 AM5/29/13
to Maëlle Delay, netlog...@googlegroups.com
I don't succeed to access to the netlogo.data

Well... the English language (unfortunately) doesn't contain enough profanities to properly express my feelings on this matter.  It seems that we have uncovered yet another terrible assumption that I made about applets, I guess, thinking that the JVM couldn't possibly refuse the system properties that it's given in the JNLP, when, in fact, it totally can and does.  They accept the properties eagerly in JNLPs through Web Start, but it seems that they really don't like people passing in system properties to even signed applets.  And it looks like this is actually something that has changed over the course of the last couple years, too—go figure.

If you're willing to switch to Web Start (which automatically downloads and launches NetLogo like a normal desktop Java application, instead of running in the browser), then the process of converting the applet JNLP into a Web Start JNLP actually isn't very difficult at all, and I know with great certainty that this method of propagating dynamic data through system properties will work for you in Web Start.  If you still want to continue with applets... there are paths forward, but they seem pretty inconvenient.  I need to think more about the case with applets to see how it can be done.  It wouldn't be so bad if we could just make a Props-like extension for reading applet arguments (like how `DefaultModel` is an applet argument), but I'm not aware of any way that a NetLogo extension could get a handle on the `Applet` object to call its `getParameter` method to get at those arguments.

Current (nasty) ideas of how this could be done with applets:
  • Make your own version of 'NetLogoJar.jar', modifying the source to (one of):
    • Make `getParameter` accessible through some public, global object that an extension could get at (I think this might be the best/easiest option of any—maybe even better than using Web Start)
    • If you know the system property name(s) ahead of time, just store the value(s) into a persistent NetLogo variable that could be accessed in the model
  • Instead of writing your data to system properties, write it to a file, pack the file into some 'resources-<UUID>.jar' file (annoying? error-prone?), automatically sign it on your web server (probably through making a Java call into your shell), maybe turn it into a '.jar.pack.gz', have the JNLP dynamically list that '.jar' as a resource, and create an extension that can look up resources on the classpath and read them (this part's pretty simple, actually).  The idea as a whole, though, is kind of sickening....
These (admittedly not very good ideas) are the best that I'm coming up with at the moment, but, if you're adamant about using applets, I'll give it some more thought.  I think I'll give the "Make `getParameter` accessible through some public, global object" thing a shot sometime tomorrow to make sure that it's viable before sending you off down another rabbit hole....


Jason Bertsche
Software Developer - NetLogo

Seth Tisue

unread,
May 29, 2013, 10:37:21 AM5/29/13
to netlog...@googlegroups.com
>>>>> "Jason" == Jason Bertsche <jason.b...@northwestern.edu> writes:

Jason> It wouldn't be so bad if we could just make a Props-like
Jason> extension for reading applet arguments (like how `DefaultModel`
Jason> is an applet argument), but I'm not aware of any way that a
Jason> NetLogo extension could get a handle on the `Applet` object to
Jason> call its `getParameter` method to get at those arguments.

I bet this is solvable, and without needing to modify NetLogo itself,
either.

In the extension code, if you can get a handle on any component in the
applet, then from there, SwingUtilities.getRoot or repeated calls to
Component.getParent should get you to the lite.Applet object.

One way of getting a handle on a component: cast your api.Context to
nvm.ExtensionContext, call its workspace() method, cast the result to
window.GUIWorkspace, call its getWidgetContainer() method, and then cast
the result to java.awt.Component. There are probably lots of other ways,
perhaps involving fewer steps, but this is the first way I can think of.

Jason Bertsche

unread,
May 30, 2013, 12:57:39 AM5/30/13
to Seth Tisue, netlog...@googlegroups.com
I bet this is solvable, and without needing to modify NetLogo itself,
either.

Awesome!

One way of getting a handle on a component: [...]

Wow, good to know.  Those instructions worked out great!


In the extension code, if you can get a handle on any component in the
applet, then from there, SwingUtilities.getRoot or repeated calls to
Component.getParent should get you to the lite.Applet object.

It looks like `SwingUtilities.getRoot` ends up shooting past the `Applet` object, but chaining calls to `Component.getParent` until reaching the `Applet` worked flawlessly.  Thanks a ton, Seth!  I'm really glad that we could do this without having to make a deviant 'NetLogoLite.jar' or implementing some terrible server-side abomination.

Alright, Maëlle, this is working now.  I've created an Applet extension that has a `get` primitive that takes just the name of the applet parameter that you want to extract as an argument.  For example, getting the applet parameter `DefaultModel` (which is currently used by applets to specify what model to load up) would be as simple as calling `applet:get "DefaultModel"` in NetLogo.  So... if you want to pass dynamic data into the applet, pass it as a parameter (like how `DefaultModel` is passed) and make the appropriate call in the NetLogo code.  That's how the Props extension and the passing-in of system properties should have worked, but... I should probably not get started with that topic again....


Jason Bertsche
Software Developer - NetLogo
Reply all
Reply to author
Forward
0 new messages