cancel
Showing results for 
Search instead for 
Did you mean: 

LinkageError at JavaMapping- UnsupportedClassVersionError in SAP PI 7.31

former_member387652
Participant
0 Kudos

Hi Experts,

I am working on SAP PI 7.31 single stack and requirement is xml to xls conversion via Java mapping and I am using eclipse mars workbench due to some issues in NWDS. My JDK version is as per attached snippet:

But after compiling the attached code it is throwing error " LinkageError at JavaMapping.load(): Could not load class: "java.lang.UnsupportedClassVersionError:: Unsupported major.minor version"" 51.0 "

Can you please suggest.

Thanks,

Nithin.

Accepted Solutions (1)

Accepted Solutions (1)

former_member387652
Participant

hi Experts,

Still I am facing the same error, " Mapping failed in runtimeLinkage Error when loading class; details: java.lang.NoClassDefFoundError, LinkageException: Linkage Error when loading class TestMap/Xml2Xls; details: java.lang.NoClassDefFoundError, NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook ". Can you please guide.

Thanks,

Naveen.

nitindeshpande
Active Contributor
0 Kudos

Hello Naveen,

What is the procedure you used to export the Jar file? Please follow the below steps to export the Jar file from NWDS and importing it in ESR -

1. Right Click on your project, click export -> java -> jar file -> click browse -> provide file name

2. Go to ESR -> Create Imported Archive -> Import Archive -> choose the above provided file name

3. Create Operation Mapping -> Use the above IA

I guess you exported the java project using General -> Archive File, hence this error.

Regards,

Nitin

former_member387652
Participant
0 Kudos

Hi Nitin,

Thank u for suggestion but I imported JAR only not whole project.

* Naveen

nitindeshpande
Active Contributor
0 Kudos

Hello Naveen,

Can you tell the procedure you followed to export the Jar file from NWDS?

Did you get a zip file or jar file after exporting?

Regards,

Nitin

former_member387652
Participant
0 Kudos

Hi Nitin,

I followed this blog .

After exporting I got JAR file which I later imported it to PI.

Thanks,Naveen.

former_member182412
Active Contributor
0 Kudos

Hi Naveen,

Why dont you use adapter modules as per this blog

Is there any specific reason you are doing java mapping??

Regards,

Praveen.

former_member387652
Participant
0 Kudos

Hi Praveen,

NWDS has issue, so why can't I use java mapping in this case?

/Nithin.

former_member182412
Active Contributor
0 Kudos

Hi Nithin,

I reused the logic used in the module, you can use below java mapping.


import java.util.ArrayList;

import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Sheet;

import org.apache.poi.ss.usermodel.Workbook;

import org.xml.sax.Attributes;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class XML2ExcelJavaMap extends AbstractTransformation {

  @Override

  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)

  throws StreamTransformationException {

  try {

  SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

  ArrayList<ArrayList<String>> contents = new ArrayList<ArrayList<String>>();

  SAXSimpleParser handler = new SAXSimpleParser(contents);

  parser.parse(transformationInput.getInputPayload().getInputStream(), handler);

  Workbook wb = new HSSFWorkbook();

  Sheet sheet = wb.createSheet("Sheet1");

  for (int i = 0; i < contents.size(); i++) {

  Row row = sheet.createRow(i);

  ArrayList<String> contentRow = contents.get(i);

  for (int j = 0; j < contentRow.size(); j++) {

  Cell cell = row.createCell(j);

  cell.setCellType(Cell.CELL_TYPE_STRING);

  cell.setCellValue(contentRow.get(j));

  }

  }

  wb.write(transformationOutput.getOutputPayload().getOutputStream());

  } catch (Exception e) {

  throw new StreamTransformationException(e.getMessage(), e);

  }

  }

  private class SAXSimpleParser extends DefaultHandler {

  private int level;

  private String fieldName = null;

  private String fieldValue = "";

  private final ArrayList<ArrayList<String>> contents;

  private ArrayList<String> row;

  public SAXSimpleParser(ArrayList<ArrayList<String>> contents) {

  this.contents = contents;

  }

  @Override

  public void startDocument() throws SAXException {

  this.level = 0;

  }

  @Override

  public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException {

  if (this.level == 1) {

  this.row = new ArrayList<String>();

  }

  if (this.level == 2) {

  this.fieldName = rawName;

  }

  this.level++;

  }

  @Override

  public void endElement(String uri, String localName, String qName) throws SAXException {

  if (this.fieldName != null) {

  this.row.add(this.fieldValue);

  }

  this.fieldName = null;

  this.fieldValue = "";

  this.level--;

  if (this.level == 1) {

  this.contents.add(this.row);

  }

  }

  @Override

  public void characters(char ch[], int start, int length) throws SAXException {

  if (this.fieldName != null) {

  char[] ch2 = new char[length];

  System.arraycopy(ch, start, ch2, 0, length);

  this.fieldValue = this.fieldValue + new String(ch2);

  }

  }

  }

}

Import poi 3.5 Final jar file as imported archive in repository.

I used the xml which you referred the thread and the Excel file created for that xml:

Regards,

Praveen.

former_member387652
Participant
0 Kudos

Hi Praveen,

Thanks for ur time, I faced error in eclipse "Type mismatch: cannot convert from HSSFWorkbook to Workbook" so I changed code to "Workbook wb = (Workbook) new HSSFWorkbook();". Now error disappeared, can I go ahead?

/Naveen.

former_member182412
Active Contributor
0 Kudos

Hi Naveen,

I did not get this error, try and let me know.

Regards,

Praveen.

former_member387652
Participant
0 Kudos

Hi Praveen,

One question, do I need to import POI 3.5 final jar as separate imported archive with different name and also the actual java program say "XML2ExcelJavaMap" with different name or Do I need to import both of them under same imported archive? Please guide.


Thanks,

Naveen.

former_member182412
Active Contributor
0 Kudos

You need to import with two different imported archives

former_member387652
Participant
0 Kudos

Hi Praveen,

Thanks a ton It worked like charm. Hope I can reuse this same mapping for all types of data structures.

/Nithin.

former_member182412
Active Contributor
0 Kudos

Hi Nithin,

Glad to hear that it worked, yes this will work for any type of structure.

Regards,

Praveen.

Answers (4)

Answers (4)

former_member387652
Participant
0 Kudos

Hi Experts,

Additional information is the JDK version installed in PI Linux server is 1.7 and the java code executed on eclipse with Java version of 1.6.

Thanks,

Naveen.

former_member387652
Participant
0 Kudos

Hi Experts,

Kindly help me to resolve the issue. My requirement is xml to xls conversion through java mapping.

Thanks,Naveen.

former_member182412
Active Contributor
0 Kudos

Hi Naveen,

Can you paste your java mapping here?

Regards,

Praveen.

former_member387652
Participant
0 Kudos

Hi Praveen,

I am using the same code as per blog https://scn.sap.com/thread/3224533 i.e., as below or else pls guide me with right code.

package JavaTest;

//import java.io.File;

//import java.io.FileOutputStream;

import java.io.IOException;

//import java.io.InputStream;

//import java.io.OutputStream;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

//import jxl.Workbook;

import org.apache.poi.hssf.usermodel.HSSFCell;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;

import org.apache.poi.hssf.usermodel.HSSFRow;

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

import org.xml.sax.SAXException;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class Xml2Xls extends AbstractTransformation

{

public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException

{

   try

   {

    getTrace().addInfo("JAVA Mapping Called");

    //Workbook w = Workbook.getWorkbook(arg0.getInputPayload().getInputStream());

  

    HSSFWorkbook wb= new HSSFWorkbook();

    HSSFSheet spreadSheet=wb.createSheet("spreadSheet");

  

    spreadSheet.setColumnWidth((short) 0,(short) (256*25));

    spreadSheet.setColumnWidth((short) 1,(short) (256*25));

  

    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();

    DocumentBuilder builder=factory.newDocumentBuilder();

  

    //InputStream xmlDocuments = null;

  Document document= builder.parse(arg0.getInputPayload().getInputStream());

    NodeList nodelist=document.getElementsByTagName("stmt");

  

    HSSFRow row=spreadSheet.createRow(0);

  

    HSSFCell cell=row.createCell((short)1);

    cell.setCellValue("Year 2005");

    cell=row.createCell((short)2);

    cell.setCellValue("Year 2004");

  

    HSSFRow row1 = spreadSheet.createRow(1);

    HSSFRow row2 = spreadSheet.createRow(2);

    HSSFRow row3 = spreadSheet.createRow(3);

    HSSFRow row4 = spreadSheet.createRow(4);

    HSSFRow row5 = spreadSheet.createRow(5);

    HSSFRow row6 = spreadSheet.createRow(6);

    HSSFRow row7 = spreadSheet.createRow(7);

    HSSFRow row8 = spreadSheet.createRow(8);

    HSSFRow row9 = spreadSheet.createRow(9);

    HSSFRow row10 = spreadSheet.createRow(10);

    HSSFRow row11 = spreadSheet.createRow(11);

  

    for(int i=0;i<nodelist.getLength(); i++)

    {

     HSSFCellStyle cellStyle=wb.createCellStyle();

     cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);

     cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);

     cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

     cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);

   

     switch(i)

     {

     case 0:

    

      cell = row1.createCell((short) 0);

      cell.setCellValue("Revenue ($)");

    

      cell=row1.createCell((short)1);

      cell.setCellValue(((Element) (nodelist.item(0)))

                    .getElementsByTagName("revenue").item(0)

                    .getFirstChild().getNodeValue());

    

      cell = row2.createCell((short) 0);

      cell.setCellValue("Cost of Revenue ($)");

    

      cell = row2.createCell((short) 1);

      cell.setCellValue(((Element) (nodelist.item(0)))

                  .getElementsByTagName("costofrevenue").item(0)

                  .getFirstChild().getNodeValue());

    

      cell = row3.createCell((short) 0);

                  cell.setCellValue("Research and Development ($)");

                

                  cell = row3.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("researchdevelopment")

                     .item(0).getFirstChild().getNodeValue());

                

                

                  cell = row4.createCell((short) 0);

                  cell.setCellValue("Sales and Marketing ($)");

                

                  cell = row4.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("salesmarketing").item(0)

                     .getFirstChild().getNodeValue());

                

                

                  cell = row5.createCell((short) 0);

                  cell.setCellValue("General and Administrative ($)");

                

                  cell = row5.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("generaladmin").item(0)

                     .getFirstChild().getNodeValue());

                

                

                  cell = row6.createCell((short) 0);

                  cell.setCellValue("Total Operating Expenses ($)");

                  cell.setCellStyle(cellStyle);

                  cell = row6.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("totaloperexpenses").item(0)

                     .getFirstChild().getNodeValue());

                

                

                  cell.setCellStyle(cellStyle);

                  cell = row7.createCell((short) 0);

                  cell.setCellValue("Operating Income ($)");

                  cell = row7.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("operincome").item(0)

                     .getFirstChild().getNodeValue());

                  cell = row8.createCell((short) 0);

                  cell.setCellValue("Investment Income ($)");

                

                  cell = row8.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("invincome").item(0)

                     .getFirstChild().getNodeValue());

                  cell = row9.createCell((short) 0);

                  cell.setCellValue("Income Before Taxes ($)");

                  cell.setCellStyle(cellStyle);

                  cell = row9.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("incbeforetaxes").item(0)

                     .getFirstChild().getNodeValue());

                

                  cell.setCellStyle(cellStyle);

                  cell = row10.createCell((short) 0);

                  cell.setCellValue("Taxes ($)");

                  cell = row10.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("taxes").item(0)

                     .getFirstChild().getNodeValue());

                  cell = row11.createCell((short) 0);

                  cell.setCellValue("Net Income ($)");

                  cell.setCellStyle(cellStyle);

                  cell = row11.createCell((short) 1);

                  cell.setCellValue(((Element) (nodelist.item(0)))

                     .getElementsByTagName("netincome").item(0)

                     .getFirstChild().getNodeValue());

                

                  cell.setCellStyle(cellStyle);

                  break;

                

     case 1:

    

    

      cell = row1.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("revenue").item(0)

                 .getFirstChild().getNodeValue());

    

              cell = row2.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("costofrevenue").item(0)

                 .getFirstChild().getNodeValue());           

            

              cell = row3.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("researchdevelopment")

                 .item(0).getFirstChild().getNodeValue());

            

              cell = row4.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("salesmarketing").item(0)

                 .getFirstChild().getNodeValue());

              cell = row5.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("generaladmin").item(0)

                 .getFirstChild().getNodeValue());

              cell = row6.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("totaloperexpenses").item(0)

                 .getFirstChild().getNodeValue());

              cell.setCellStyle(cellStyle);

              cell = row7.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("operincome").item(0)

                 .getFirstChild().getNodeValue());

              cell = row8.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("invincome").item(0)

                 .getFirstChild().getNodeValue());

              cell = row9.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("incbeforetaxes").item(0)

                 .getFirstChild().getNodeValue());

              cell.setCellStyle(cellStyle);

              cell = row10.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("taxes").item(0)

                 .getFirstChild().getNodeValue());

              cell = row11.createCell((short) 2);

              cell.setCellValue(((Element) (nodelist.item(1)))

                 .getElementsByTagName("netincome").item(0)

                 .getFirstChild().getNodeValue());

              cell.setCellStyle(cellStyle);

              break;

           default:

              break;

           }

     }

  

    wb.write(arg1.getOutputPayload().getOutputStream());

      

   // FileOutputStream output = new FileOutputStream(new File("IncomeStatements.xls"));

      //    wb.write(output);

       //   output.flush();

        //  output.close();

       } catch (IOException e)

       {

      

       } catch (ParserConfigurationException e) {

   // TODO Auto-generated catch block

   e.printStackTrace();

  } catch (SAXException e) {

   // TODO Auto-generated catch block

   e.printStackTrace();

  }

     

   

    }  

}

Please use the sample xml attached in the blog https://scn.sap.com/thread/3224533

Thanks,

Naveen.

bhavesh_kantilal
Active Contributor
0 Kudos

SAP PI 731 supports JDK 1.6

Right Click on your project --> Properties --> Java Compiler --> Enable Project Specific Settings --> and change the compliance level to 1.6

See below screen shot:

former_member387652
Participant
0 Kudos

Hi Bhavesh,Praveen,

Thanks for your reply.

Now I am facing Linkage error during runtime. Mapping failed in runtimeLinkage Error when loading class TestXML/test; details: java.lang.NoClassDefFoundError, LinkageException: Linkage Error when loading class TestXML/test; details: java.lang.NoClassDefFoundError, NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook

Please suggest.

Thanks,

Nithin.

former_member182412
Active Contributor
0 Kudos

Hi Nithin,

You did not include the Excel related external jar files in the jar which you exported.

Regards,

Praveen.

iaki_vila
Active Contributor
0 Kudos

Hi Naveen,

You must download the jar (Download jakarta-poi-2.5.jar : jakarta&amp;nbsp;&amp;laquo;&amp;nbsp;j&amp;nbsp;&amp;laquo;&amp;nbsp...) and import it like library in your SAP NWDS.

Regards.

former_member387652
Participant
0 Kudos

Hi Praveen,

In eclipse no warning/errors are thrown after importing the JARS. Below first snippet shows JARS I included in external library and my requirement is xml to xls conversion for which I am trying out the attached code. Please help.

I am using code for xml to xls conversion following link:  https://scn.sap.com/thread/3224533 .

But I am still facing error.

Thanks,

Nithi.

former_member182412
Active Contributor
0 Kudos

Hi Nithin,

You can create a folder add the jars to the folder.

When you export the jar select below option.

Regards,

Praveen.

iaki_vila
Active Contributor
0 Kudos

Hi Naveen,

Are you sure the jars imported are compiled for the java version that you are using?.

Some deprecated classes could raise issues.

Regards.

former_member387652
Participant
0 Kudos

Hi Inaki,

How to check whether the jars I imported are complied for java version that I am using. The java version installed on local desktop is 1.7.0_45.

Thanks,

Naveen.

former_member387652
Participant
0 Kudos

Hi Praveen,

I have created a source folder named "lib" but unable to add the jars which are highlighted in snippet to that created folder highlighted in snippet , can you please guide.

Thanks,

Naveen.

former_member387652
Participant
0 Kudos

Hi Inaki,

I have downloaded the above jar file, but still facing the same issue. Kindly guide.

/Naveen.

former_member182412
Active Contributor
0 Kudos

Hi Nithin,

Keep the jar files in a any folder in your laptop and Just drag and drop into lib folder. Don't need to include sap libraries like mapping jar which you have in the list.

Regards,

Praveen.

former_member387652
Participant
0 Kudos

Hi Praveen,

Thank you for your time. I have imported all the jars in to source folder, but still the same error.

" Mapping failed in runtimeLinkage Error when loading class TestMap/Xml2Xls; details: java.lang.NoClassDefFoundError, LinkageException: Linkage Error when loading class details: java.lang.NoClassDefFoundError, NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook "

    

Thanks,

Naveen.

former_member182412
Active Contributor
0 Kudos

Hi Naveen,

You compile the java mapping code with JDK 1.7 and your PI version supports JDK 1.6 that is why you are getting above error.

Right click on your project and Build Path->Configure BuildPath->Java Compiler, change it to 1.6 and export the jar file and import into ESR.

Regards,

Praveen.