This site requires JavaScript, please enable it in your browser!
Greenfoot back
Herlix
Herlix wrote ...

2014/5/8

Exporting A Greenfoot Project with Native Libs

Herlix Herlix

2014/5/8

#
Hi! I'm having problem adding native java libraies. My Project works while not exported. Using Secure Shell connecting to a server and saving / Reading data. I need to export it but can't get it to work. The guide ain't really that clear. http://www.greenfoot.org/doc/native_loader/ But how do I use it? i've added my jars where they are suppose to be added. But don't understand where to add the code and what the code is suppose to say. I get syntax error all the time too. // Herlix
davmac davmac

2014/5/9

#
The page you linked to above has all the information you need, I think, including an example:
    static {
        final NativeLoader loader = new NativeLoader();
        
        loader.addClasspath( ".\\+libs\jinput.jar" );
        loader.loadClass( "net.java.games.input.ControllerEnvironment" );
    }
You would most likely put this code in your world class. You cannot export projects with native libraries and have it work automatically; you would need to copy the native libraries to the same location as your exported jar file. You cannot use native libraries at all if you upload to the greenfoot.org site.
Herlix Herlix

2014/5/9

#
Well, I'm trying to put that in my world class, but where? and I get a syntax error even from copying the exact same code. That's whats confusing me. I've added the class needed, moved my jars to where I need them. But do I need to change the loader class to "extends BoulderDash" (the world)? and Why can't I even use the example code? "Illegal escape character" is the error I allways get.
davmac davmac

2014/5/9

#
Ah - there's one small error in that code, you need to double the backslash:
    static {  
        final NativeLoader loader = new NativeLoader();  
          
        loader.addClasspath( ".\\+libs\\jinput.jar" );  
        loader.loadClass( "net.java.games.input.ControllerEnvironment" );  
    }  
(Or use forward slashes instead, which will also work on other systems - Mac and linux). I'll fix the page.
But do I need to change the loader class to "extends BoulderDash" (the world)?
No! Why do you think you need to do that?
Herlix Herlix

2014/5/9

#
Thanks! =)
Herlix Herlix

2014/5/9

#
I've exported it but it's not starting (only as a process). Something wrong in this? : static { final NativeLoader loader = new NativeLoader(); loader.addClasspath( ".\\+libs\\com.jcraft.jsch.jar" ); loader.addClasspath( ".\\+libs\\mysql-connector-java-5.1.30-bin.jar" ); loader.loadClass( "com.jcraft.jsch.JSch" ); loader.loadClass( "com.jcraft.jsch.Session" ); loader.loadClass( "java.sql.Connection" ); loader.loadClass( "java.sql.DriverManager" ); loader.loadClass( "java.sql.ResultSet" ); loader.loadClass( "java.sql.Statement" ); } ?
davmac davmac

2014/5/9

#
Ah. In general, you can't use external jar files in exported scenarios. You may be able to create a combined jar by extracting the files from each jar (your scenario, the jsch jar and the mysql connector jar) into a common location, then jar-ing the result. (The jar file format is the same as the zip format, so you can use eg Winzip to extract and create jar files) However, what you've written looks like it should probably work when you run your scenario within Greenfoot. Does it?
Herlix Herlix

2014/5/9

#
It runs fine inside greenfoot! =) Now i just got to figure out the export. I'm going to try what you gave me. Thanks so far ;)
Herlix Herlix

2014/5/9

#
The problem is I don't know what to keep in the jar files. I've tried adding all the maps 3x in each map into the gf map. Is there anyway to keep the jard outside the Greenfoot project and use them?
Herlix Herlix

2014/5/10

#
Can Greenfoot read libs outside its own map? Like a map just beside the exported jar file? Ex: loader.addClasspath( "lib\\.\\com.jcraft.jsch.jar" ); ? that syntax is wrong ofc. My question would be what would the syntac look like? // Alex
You need to login to post a reply.