In Built Java function or macro for calling in batch script

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

In Built Java function or macro for calling in batch script

Post by DSRajesh »

Dear All,

I need to call java class in a batch script so that java class will triggered using datastage job and it will decrypt the encrypted files.

Is there any java specific function/macro which can be used in datastage server jobs?

How to approach for this other than java packs?
RD
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

If the decryption process outputs the decrypted data to standard out, you could probably use an External Source stage to trigger the decryption. If the decryption process writes the decrypted data to a file, then perhaps an External Command activity in a job sequence or a BeforeJob ExecSH call in the parallel job.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

Hi ,

First thing is i need to trigger the java class which is on datatsage server so that the decryption process will start using java class and encrypted file will be decrypted.

Also this has to be done using the batch script in server jobs but not the parallel jobs.

Can any one suggest me on this.
RD
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

To follow on my original suggestions, these are applicable in server jobs as well (a job sequence is usable in either case). Have you as yet tried anything and how successful/unsuccessful were the attempts?

When executed, does your shell script write the decrypted data into another file, or does it output to standard out (console)?

A) If the script writes the decrypted data to a file, you can use either the Before-Job Subroutine job property (ExecSH) in the server job OR an Execute Command activity in a job sequence to decrypt the file prior to the server job reading it.

B) If the script outputs the decrypted data to the console (standard out), you can call the script using a Filter Command in the server Sequential File stage OR you can use a Command Stage to execute the script and pass the data in the output link.

Very similar to what I suggested in my original reply.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

Dear James

Server is on windows..so need to use batch script for this rather than shell script.

Can you please suggest any batch script where we can call java function..
RD
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Server is on windows..so need to use batch script for this rather than shell script
You indicated Unix as the O/S when you opened this thread. Please ensure that you provide accurate information when requesting help!

Running java code is essentially the same in windows as in linux or unix. Ensure that your path is correct (contains the proper java bin folder), include the proper libraries in your classpath environment variable (separated by semicolons ; ) and execute the java class using the java command and it's command-line options. I would assume that the developer of the decryption class has provided some instructions for using it.

Have you successfully run the decryption step from a windows command prompt? I would suggest you do that so you know you can execute the class and provide the correct options/arguments to it.

Your java class (and any required libraries/jar files/classes) will need to be located on a drive and folder that is accessible by your windows server.

Something to start with from which you can build your batch script (obviously you will need to modify it!):

Code: Select all

@echo off
set ASB_NODE_HOME=C:\IBM\InformationServer\ASBNode
set JAVA_HOME=%ASB_NODE_HOME%\apps\jre
set JAVA_HOME=%ASB_NODE_HOME%\apps\jre
set HOME_DIR=C:\DecryptClass\
echo %ASB_NODE_HOME%
echo %_JAVACMD%

set CLASSPATH=%ASB_NODE_HOME%\conf
set CLASSPATH=%CLASSPATH%;%HOME_DIR%\library_filename_1
REM repeat the above for as many libraries as you need to load

%_JAVACMD% [any_java_options_you_may_need_to_set_per_the_developer] -classpath %CLASSPATH% the_name_of_the_decrypt_class %1
Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

Hi James,

what are all the options will be there as part of %_JAVACMD% and what are the libraries needed to decrypt ascii files in windows.

also do we have to pass the file name to the javacmd so that it trigger java class to decrypt the particular file. if it is the case how can pass the filename.

Please suggest me here.
RD
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

what are all the options will be there as part of %_JAVACMD%
In that example batch script, %_JAVACMD% is strictly an environment variable (similar to using $varname for environment variables in unix shell scripts) containing the command to run java (java.exe in Windows). The [any options....] bit was contained within [ brackets ], common nomenclature to indicate optional content--in this case, options for java that the java class you're using may require.
what are the libraries needed to decrypt ascii files in windows
Honestly, how would I be expected to know? :?: You have obtained (by some method--local developer/friend/website?) a java class that will somehow allow you to decrypt a file. The developer(s) of that java class should have provided the necessary instructions for using the class, including any required libraries and/or jar files, how to call the class' functions (or if it's a main() java class, how to execute it and what parameters are required)...in general: How it works and how to use it. If it's a publicly available java class (i.e. obtained from the net), you should be able to google for it and find appropriate documentation.
do we have to pass the file name to the javacmd so that it trigger java class to decrypt the particular file. if it is the case how can pass the filename
I sure don't know...what do the instructions/documentation for the java class you're using say? How the class works and how you provide the information it needs to work will dictate how you will use it either inside or outside DataStage.

If you don't know how to use java at all, then you need to either:
1) Find someone in your location that does and ask for their assistance, or
2) Begin educating yourself about java. There are plenty of on-line resources (java forums/tutorials/references/etc.) and plenty of books. This DataStage forum is not the appropriate place to teach you java.

The same is true of Windows batch files...if you don't know what they are and how to use them, you need either local assistance or education. I've given you a skeleton batch file in my previous to start with (yes, the syntax is just a little different that unix shell scripts, but the concept is the same).

I believe this thread has probably reached or exceeded the limit of it's DataStage usefulness as it has evolved from "how can I call Java from within DataStage to perform a certain function?" (for which you were clearly provided several options to explore) to essentially "how do I use Java?", which is way outside the purpose of this forum. You've been provided with all you need from a DataStage perspective to perform what you requested assistance with--executing a script within DataStage to decrypt a file. Documentation on the DataStage options provided is available online (and included with Information Server) in the appropriate Information Center for the version of IS/DS you are using.

Good luck and best regards!
- james wiles


All generalizations are false, including this one - Mark Twain.
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

Dear James,

There will be no ASB_NODE concept as part of Server version in datastage 7.5.

In such case ,what will the Java Home value with out ASB NODE HOME as in set JAVA_HOME=%ASB_NODE_HOME%\apps\jre.
RD
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

Thanks for your valuable suggesions.

You have provided the 3 variables wrt IBM Datastage 8.x perspective.
But my question pertain to Datastage 7.5....for which paths will differ ...

I am not looking for Java tution from you :)

I am looking for an Java API which will be used as part of Batch Script.
RD
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That's the thing James has been trying to tell you - there is no "Java API" for a script. You simply run Java itself just like any other command and pass it the name of the jar file to execute. That or you use one of the tools available to turn the jar file into an executable and run that.

As to the paths to use, they simply need to point to wherever you have Java installed on your system. That could be a stand-alone version or you could leverage the version distributed with DataStage. In either case that path should be easily discoverable by you if you take a moment or two and look.
-craig

"You can never have too many knives" -- Logan Nine Fingers
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

DSRajesh,

I've been answering your questions based on the expectation that you already have a java class or program that performs the decryption, you know how it works and you were requesting information on how to execute it by calling a script from DataStage...this is what your original question led me to believe:
I need to call java class in a batch script so that java class will triggered using datastage job and it will decrypt the encrypted files
If you DON'T have a java class or program that will decrypt your files, then it is up to you to acquire one...I don't know your decryption requirements (what type of encryption is used, etc.)...YOU do (hopefully). Google for "file decryption using java" and start with what's returned. Include the encryption type in the search if possible to narrow down the results.

If you don't have access to the server to find where java is installed on it, then you need to engage the system administrator or whomever is responsible to software installation and maintenance for the server and ask them. Once you have that information, determine if it meets the minimum requirements for your decryption class.

If you need java installed on your workstation, download it from www.java.com

The command structure for running java from the command line or within a script is:

Code: Select all

java [-options] class [args....]      to execute a class
java [-jar] [-options] jarfile [args....]     to execute a jar file
Java Windows Tutorial

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Just so the example is clear:
You have provided the 3 variables wrt IBM Datastage 8.x perspective.
But my question pertain to Datastage 7.5
The variable names in my example batch script are just that: names. They are what they are because the script I pulled them from uses the java included with Information Server and it makes it convenient to port the code from one IS environment to another without major changes to the script. The names of the variables are NOT important...the CONCEPT is the important part. %JAVA_HOME% points where java.exe is located. %ASB_NODE_HOME% just happens to point to where ASBNode is located because the java I ran with the script uses some of ASBNode's libraries (that's why it's used in building %CLASSPATH%). Change the names to whatever YOU want them to be (except %JAVA_HOME%--leave that one as is) and set the values to what YOU require.

Enough said
- james wiles


All generalizations are false, including this one - Mark Twain.
Post Reply