dansmith65 Posted January 10, 2011 Posted January 10, 2011 I have been playing with the ScriptMaster plug-in for the last few days and was stumbling through creating a .jar file with my own code, which could be accessed from any function. Since I did not find any information on how to do this in this forum, I thought I would add my findings here... I used the 'CreateFolder' function included with ScriptMaster as an example. 1. Write Class Code class MyFunctions{ def CreateFolder(path){ File dir = new File(path); if( dir.exists() ) return false; if( dir.mkdirs() ) { //Success! return true; } else { //Figure out why it failed File realParent = dir; while( realParent != null && ! realParent.exists() ) { realParent = realParent.getParentFile(); } if( realParent != null && !realParent.canWrite() ) { throw new FileNotFoundException("Directory " + dir.getAbsolutePath() + " could not be created because the parent directory " + realParent.getAbsolutePath() + " is not writeable" ); } else { throw new FileNotFoundException("Directory + " + dir.getAbsolutePath() + " could not be created because of an unknown error." ); } } } } Save File As: MyClasses.java the class name should begin with an uppercase letter (or so I read somewhere) 2. Compile Download Java JDK Download Groovy * To Compile: run from the command line: groovyc MyClasses.java (this will create a MyClasses.class file) 3. Create .jar file run from the command line: jar cf MyJar.jar MyFunctions.class (this will create a MyJar.jar file) 4. Add .jar to ScriptMaster.fp7, test go to 'Jar Libraries' create new record, insert the MyJar.jar file go to 'ScriptMaster Modules' create a New Record, give your test function a name select the MyJar.jar file on the 'Jars' tab create a parameter named: pathToCreate enter this code for the function example = new MyFunctions() example.CreateFolder(pathToCreate)cross your fingers **, hoping it will work, then run the script * Groovy is optional, you could write your class entirely in Java, then use 'javac' to compile rather than 'groovyc' ** finger crossing is also optional
Recommended Posts
This topic is 5135 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now