Generic way to obtain jar files for any Java Class and download the files as a zip
Addition 2 on 25/07/2017: The bean will download the (jar) files as a zipped file on the receiver channel.
When moving across different clients, it can take some time to set up NWDS with all the jar files required for development. Otherwise, sometimes while staring a new development, it can take some time to find the jar files required. This blog describes a generic approach to find the jar files for a list of files.
The approach has been already covered in previous blogs like this link.
However, the class name is hardcoded and I was thinking of creating a generic solution where I can just plug an adapter module and it will retrieve the jar files for a list of classes.
Bean Name: FindClassPathBean
It doesn’t need any parameters and tries to find the jar files for each of the lines which are expected to be class names.
Create an ICO/iFlow with a SOAP sender and ftp adapter as receiver.
For this example, below is the list of classes for which we’re getting an error in NWDS as we don’t have the jar files set up in our project.
Remove the import and semi-colons to just get the class names.
This list of class names can be used in the test tool.
Chose Testing Tab->Send Test Message
Here in payload the list of classes can be supplied for which we’re interested in finding the jar files.
Send the message and we get the logs with the jar locations !
It’s really handy if we have a large set of files to work through.
The bean blanks out the message as we don’t want to write any file to the target FTP server. FTP adapter has been configured to ignore blank messages .
and from the adapter log indicates FILE_SUC_EMPTYPAYLOAD indicating empty message has been received by the FTP adapter. On a side note, I’m not sure why SAP chose this cryptic string instead of writing the text that an empty message has been received and nothing will be written to the end-point.
This enables us to navigate the file path as mentioned in this blog link .
This is the github link which has the EAR file which we can be deployed to the PI server and can be used straight away.
My test was done on a PO 7.4 system.
An idea was put forward in one of the comments to download the files.
The second revision reads the files and downloads the files as a zipped file in the target directory.
Put the class names. As a test I have put the class name of the bean itself.
The logs indicate the files being read.
The log confirms the file has been written.
if we download and open the file, it shows the jar files which have been added.
So using this bean, we’re able to display the jar paths and download the jar files as a single zipped file. internally, it’s using a set to store the class name and hence a jar file will be added to the zip only once even if it corresponds to multiple classes.
Nice and elegant solution...
can i enhance the code so that, once i test the scenario, it creates zip file which contains all jar files?
I've enhanced it to download the jars as a zipped file now 🙂 .
Thank you Vikas for your time to enhance this.
This will be more helpful for PI/PO folks during java development. Not all are having access to PI server file level access. They can skip going to basis team.
Thanks for sharing this.
But I guess the easiest way is to put the same code into UDF, and just run the test in MM to get desired class(es) locations. 🙂
This is what are talking about ryt : https://blogs.sap.com/2014/05/23/simple-way-to-find-sap-pipo-java-class-jar-files-location/
I usually use this fast and convenient.
I haven't read the mentioned blog before, but Praveen went the same way I did 🙂 Just copied the code into UDF. I did the same :-).
Hi Evgenly/ Manoj,
yes we can definitely do the message mapping and UDF. it's just that I moved between different clients and was looking to create a bean to do give me the file locations easily for a large group of missing classes and I'm too lazy to create a message map for it. It doesn't help that I can't access ESR now ( for some other reason ) and only had access to integration builder.
I've given the link of other blogs as that's where I got the idea - just decided to enhance it.
Nice blog indeed.
But, why it is even required to add separately jar files in your JAVA mapping or custom module development project when it is not external jar files but SAP internal jar files.
We can always add XPI mapping/adapter library in our java project which will add all required jars automatically.
There are lots of classes used in Adapter framework which are not included in XPI adapter library.
For example, you can try to use XMBMessageOperator class in your code.
I was building an adapter and not a map or custom module in this case.
Earlier, I was building a Java proxy which reads AS Java database and there were other libraries required.