Execute Java Class File from SSIS
Posted by Sunil Reddy Enugala on June 2, 2013
Hi, recently I came across interesting requirement through my friend Goutham Aakiti. The requirement is like processing Java Class file using SSIS. I was very curious to know how to achieve this, spent some time and found that there are two ways to process Java Class File.
Let me show how we can do this.
I have a Java Class File which deletes a file. Please go through the below Java code which accepts file path as argument to delete a file.
If you compile the above Java Code, the compiler will generate binary code file which is called as Class File. We will be using the Java Class file further to delete file.
Drag a Execute Process task component to the SSIS Control Flow designer pane
Create four variable to pass the property values dynamically.
FilePath: Represents the path of the file which we are about to delete.
JavaClass: Represents the path of Java Class file which we use to delete a file.
JavaDir: Represents the path of Java.exe, which we use to execute Java Class file.
WorkingDir: Represents the Folder path of Java.exe.
Only variables like FilePath, JavaClass and JavaDir needs input. We need to set variable expression for WorkingDir variable.
Please go through the below figure to know about setting of variable expression for WorkingDir variable. Click on WorkingDir variable and select properties(press f4 ). Set the EvaluateExpression value to True. Set the Expression value as below.
SUBSTRING( @[User::JavaDir] , 1, LEN( @[User::JavaDir] )-FINDSTRING(REVERSE(@[User::JavaDir]),"\\",1)+1)
Please go through the below figure to know about the property values of Execute Process task.
Executable property needs the path value of Java.exe, we will be passing the value through JavaDir variable as an property expression.
Arguments property needs statement to execute the Java Class File.
WorkingDirectory property needs the folder path of Java.exe, we’ll be passing the value through WorkingDir variable.
Please go through the below figure to know about the setting of above properties values. Properties like Executable and WorkingDirectory will be getting values directly from variables like JavaDir and WorkingDir.
We need to set an expression for Arguments property, please go through the below figure to know about the setting of expression.
"-classpath " + SUBSTRING( @[User::JavaClass] , 1, LEN( @[User::JavaClass] )-FINDSTRING(REVERSE(@[User::JavaClass]),"\\",1)+1) + " "+SUBSTRING (@[User::JavaClass], LEN( @[User::JavaClass] ) – FINDSTRING( REVERSE( @[User::JavaClass] ), "\\", 1) + 2, LEN (RIGHT( @[User::JavaClass], FINDSTRING( REVERSE( @[User::JavaClass] ), "\\", 1 ) – 1 ) ) – FINDSTRING( REVERSE( @[User::JavaClass] ), ".", 1 ) ) + " "+ @[User::FilePath]
Lets see how it works.
I want to delete a file DelmeSoon.txt from path D:FileDeletion\DellmeSoon\
press f5 and see, the Java Class file will deletes the.
Let me know your comments and queries on my post.
This entry was posted on June 2, 2013 at 5:03 pm and is filed under MS BI Related. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.