hiteksoftware.com Forum Index hiteksoftware.com
User discussion forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can I access a custom code library in Java (JAR).

 
Post new topic   Reply to topic    hiteksoftware.com Forum Index -> Task Sequences, Chains and Scripts
View previous topic :: View next topic  
Author Message
bacon78



Joined: 10 Jan 2008
Posts: 3

PostPosted: Thu Jan 10, 2008 6:17 am    Post subject: How can I access a custom code library in Java (JAR). Reply with quote

I have been trying to build a custom code library that could be reused across our numerious scripts in out environment. We have come accross a good amount of logic that can be located in a single resource, if possible. I am mainly a .Net developer and fairly new to Java coding.

I have downloaded new JDBC Drivers for connecting to SQL Server "com.microsoft.jdbc.sqlserver.SQLServerDriver" and got everything to work. From this experience I was hoping I could achieve my goals by compiling my own library and accessing it in Script Tasks.

I have created a new test class and compiled it into a JAR. I then copied the JAR into the JRE\Bin folder. I have also modified the ClassPath System Variable value to include this location.

Any help would be great thanks!

Test Class is as follows
==========================
Code:

package com.horizonhobby.logility;
/* Imports */
import com.hitek.engine.mods.script.*;
public class Automize
{
   public Automize(){}
   
   public void writeLogInfo(String Msg){
      System.out.println("Started");
      Script.run("AutoTest");
      System.out.println("Finieshed");
   }
}

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

Here is a secon Test class that I added to the JAR to see if there would be compile / run time errors but everything works, except for nothing output to the Activilty Log
==========================
Code:

import com.horizonhobby.logility.*;
public class TestAutomize {
   public static void main(String[] args) {
      System.out.println("Void Main First");
      Automize myAutomize = new Automize();
      myAutomize.writeLogInfo("Brads Test");
   }
}

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

Here's the Sql JDBC Example
==========================
Code:

import com.hitek.engine.mods.script.Script;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;
import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;

String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://ServerName:Port#;DatabaseName=DBName;";
String username = "Username";
String password = "Password";
Connection connection = null;
Class.forName(driverName);
Driver d = (Driver)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT Top 10 * FROM Steps");
while (rs.next()) {
   s = rs.getString("Name");
   Script.act("Step Name: " + s);
   Script.out("Step Name: " + s);
}

==========================
Back to top
View user's profile Send private message MSN Messenger
melvin
Site Admin


Joined: 25 May 2006
Posts: 595
Location: Santa Barbara, california

PostPosted: Thu Jan 10, 2008 7:22 pm    Post subject: Reply with quote

1) To output to output log, use:
Script.out("test");

2) All jars in the main Automize folder are automatically added to classpath when launching the engine from user interface.

3) The other option is to launch the user interface and engine using batch files. Sample Automize.bat file is located in the main install folder. simply drop your .jar into Automize7 main folder and add the jar name to the launch code in the batch file.
Back to top
View user's profile Send private message Send e-mail
bacon78



Joined: 10 Jan 2008
Posts: 3

PostPosted: Fri Jan 11, 2008 5:48 am    Post subject: Reply with quote

I have tried dropping my JAR into the following and have not had any luck.

    C:\Program Files\Automize7
    C:\Program Files\Automize7\jre
    C:\Program Files\Automize7\jre\bin


To get the custome Sql Server JDBC Drivers to work I had to drop the three JAR files into the "C:\Program Files\Automize7\jre\bin" folder. Before that I was getting an invalid Classpath error.

Due to the fact that I am a .Net developer not a Java developer I am still trying to pick this up and it might be that fact that I am new to the errors that I am recieving.

Any help would be great.

Thanks

Here's my test Script trying to call my test class in my JAR.
Script Name = "NewJarTest"
=============================================
Code:

import com.hitek.engine.mods.script.*;
import com.horizonhobby.*;
import com.horizonhobby.logility.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;

Automize myA = new Automize();
myA.writeLogInfo("Brads Test");

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

Sript name = "AutoTest"
=============================================
Code:

import com.hitek.engine.mods.script.Script;
import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;

Script.out("It Worked");

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


Error being recieved
=============================================
Code:



Error Message: Sourced file: C:\Program Files\Automize7\data\scripts\testing_script : Typed variable declaration : Class: Automize not found in namespace



Error stack trace: Sourced file: C:\Program Files\Automize7\data\scripts\testing_script : Typed variable declaration : Class: Automize not found in namespace : at Line: 9 : in file: C:\Program Files\Automize7\data\scripts\testing_script : Automize


   at bsh.BSHAmbiguousName.toClass(Unknown Source)

   at bsh.BSHType.getType(Unknown Source)

   at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)

   at bsh.Interpreter.eval(Unknown Source)

   at bsh.Interpreter.source(Unknown Source)

   at bsh.Interpreter.source(Unknown Source)

   at com.hitek.gui.mods.script.Scripts.test(Scripts.java:278)

   at com.hitek.gui.mods.script.Scripts.actionPerformed(Scripts.java:209)

   at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

   at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)

   at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

   at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

   at java.awt.Component.processMouseEvent(Unknown Source)

   at java.awt.Component.processEvent(Unknown Source)

   at java.awt.Container.processEvent(Unknown Source)

   at java.awt.Component.dispatchEventImpl(Unknown Source)

   at java.awt.Container.dispatchEventImpl(Unknown Source)

   at java.awt.Component.dispatchEvent(Unknown Source)

   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

   at java.awt.Container.dispatchEventImpl(Unknown Source)

   at java.awt.Window.dispatchEventImpl(Unknown Source)

   at java.awt.Component.dispatchEvent(Unknown Source)

   at java.awt.EventQueue.dispatchEvent(Unknown Source)

   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

   at java.awt.EventDispatchThread.run(Unknown Source)

Finished Testing Scripts

=============================================
Back to top
View user's profile Send private message MSN Messenger
melvin
Site Admin


Joined: 25 May 2006
Posts: 595
Location: Santa Barbara, california

PostPosted: Fri Jan 11, 2008 6:13 am    Post subject: Reply with quote

1) hitek7.jar also has an Automize class. rename the class and see if the error goes away..
2) what is the hierachy of the Automize class in your jar?
Back to top
View user's profile Send private message Send e-mail
bacon78



Joined: 10 Jan 2008
Posts: 3

PostPosted: Fri Jan 11, 2008 6:33 am    Post subject: Try it again - no luck and this is the all the code. Reply with quote

Automize Script to Test Java JAR Class
Code:

import com.hitek.engine.mods.script.*;
import com.horizonhobby.*;
import com.horizonhobby.logility.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;

HHAutomize_Logility myA = new HHAutomize_Logility();
myA.writeLogInfo("Brads Test");


Error Reported
Code:

Error Message: Sourced file: C:\Program Files\Automize7\data\scripts\testing_script : Typed variable declaration : Class: HHAutomize_Logility not found in namespace

Error stack trace: Sourced file: C:\Program Files\Automize7\data\scripts\testing_script : Typed variable declaration : Class: HHAutomize_Logility not found in namespace : at Line: 9 : in file: C:\Program Files\Automize7\data\scripts\testing_script : HHAutomize_Logility

   at bsh.BSHAmbiguousName.toClass(Unknown Source)
   at bsh.BSHType.getType(Unknown Source)
   at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)
   at bsh.Interpreter.eval(Unknown Source)
   at bsh.Interpreter.source(Unknown Source)
   at bsh.Interpreter.source(Unknown Source)
   at com.hitek.gui.mods.script.Scripts.test(Scripts.java:278)
   at com.hitek.gui.mods.script.Scripts.actionPerformed(Scripts.java:209)
   at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
   at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)

Finished Testing Scripts


Java JAR Information
Project Name: Logility
Folder Name: com.horizonhobby.logility
Package: com.horizonhobby.logility

HHAutomize_Logility.Java
Code:

package com.horizonhobby.logility;
/* Imports */
import com.hitek.engine.mods.script.*;
public class HHAutomize_Logility
{
   public HHAutomize_Logility(){}
   
   public void writeLogInfo(String Msg){
      System.out.println("Started");
      Script.run("AutoTest");
      System.out.println("Finieshed");
   }
}


TestAutomize.Java
Code:

package com.horizonhobby.logility;

public class TestAutomize {
   public static void main(String[] args) {
      System.out.println("Void Main First");
      HHAutomize_Logility myAutomize = new HHAutomize_Logility();
      myAutomize.writeLogInfo("Brads Test");
   }
}
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    hiteksoftware.com Forum Index -> Task Sequences, Chains and Scripts All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group