Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.NoClassDefFoundError in Eclipse at runtime

807588Sep 2 2008 — edited Jan 20 2009
Hi All,
I am running this program in Eclipse 3.2.
I am calling a method executeOperation() in ExtractBomOperation class by instantiating its object from ExtractBomDialog class and then calling that method. However at executeOperation() at the line
"wb = new HSSFWorkbook();" I am getting a run time error that in Eclipse console shows as : "java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook" . I have already included poi.jar file in Eclipse.
I am sending the ExtractBomDialog and ExtractBomOperation class codes below.
Please note some packages/API are exclusive to the tool in which I work.

Not sure why I am getting the error.Any help would be great.
Thanks in advance.



/* Begin Code for ExtractBomDialog class */

package com.teamcenter.project.rac.tcapps.pse.commands.extractbom;

//imports
//import com.ugsolutions.aif.*;
//import com.ugsolutions.iman.kernel.*;
import com.teamcenter.rac.util.*;

import com.teamcenter.rac.aif.*;
import com.teamcenter.rac.aif.kernel.*;
import com.teamcenter.rac.kernel.*;

//import org.apache.poi.hssf.usermodel.*;
//import org.apache.poi.hssf.util.*;
//import org.apache.poi.hssf.usermodel.HSSFWorkbook;


//import com.teamcenter.rac.util.*;
//import com.teamcenter.pune.rac.tcapps.pse.extractbom.utils.*;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import javax.swing.filechooser.*;





//import javax.swing.filechooser.*;



public class ExtractBomDialog extends AbstractAIFDialog implements InterfaceAIFOperationListener
{
static final long serialVersionUID = 1L;
ExtractBomPanel dataToXlsPanel = null;
JPanel buttonPanel = new JPanel();
JButton ok = new JButton();
JButton cancel = new JButton();
boolean isOk = true;
TCComponentBOMLine bom_line=null;

ExtractBomOperation oper;

AIFDesktop desktop = null;
Frame parent = null;
TCSession session = null;





/*private TCComponentBOMLine ctx = null ; // = null;
//private TCComponentBOMLine bom_line; //= null;
//private TCComponent comp ; //= null ;
private int currentRow = 0;
private String fileName = null;
private HSSFRow titlerow = null;
private HSSFCellStyle styleShaded = null;
private HSSFCellStyle styleNormal = null;
private HSSFCellStyle styleHeader = null;

//private HSSFWorkbook wb = null;
private FileOutputStream fileOut = null;
private HSSFSheet sheet = null;

public final static int DATE_COL = 0;
public final static int ITEM_COL = 1;
public final static int REV_COL = 2;
public final static int NAME_COL = 3;
public final static int OWNER_COL = 4;
public final static int GROUP_COL = 5;
public final static int RELSTAT_COL = 6;
public final static int TYPE_COL = 7;
public final static int UOM_COL = 8;

//public final static String DATE_DESC = "Creation Date";
public final static String ITEM_DESC = "Item Id";
public final static String REV_DESC = "Rev";
public final static String NAME_DESC = "Name";
//public final static String OWNER_DESC = "Owner";
//public final static String GROUP_DESC = "Owning Group";
//public final static String RELSTAT_DESC = "Status(es)";
//public final static String UOM_DESC = "UOM";
public final static String TYPE_DESC = "Item Description";

// public final static short DATE_WID = 12;
// public final static short OWNER_WID = 15;
// public final static short GROUP_WID = 15;
//public final static short UOM_WID = 5;
public final static short ITEM_WID = 32;
public final static short REV_WID = 4;
public final static short NAME_WID = 32;
//public final static short RELSTAT_WID = 10;
public final static short TYPE_WID = 20;*/




/**
* Displays the dialog
*
* @param parent
* the parent UI component
*/

public ExtractBomDialog( Frame parent,TCComponentBOMLine bl)
{
super(parent,false);
JOptionPane.showMessageDialog(new JFrame(),"Inside AMATExtractBomDialog constructor","Alert",JOptionPane.ERROR_MESSAGE);
session = (TCSession)bl.getSession();
this.parent = parent;

if ( parent instanceof AIFDesktop )
{
desktop = (AIFDesktop)parent;
}
try
{
initializeGUI();
}catch( Exception e )
{
e.printStackTrace();
}
}

/**
* Builds the UI (from JBuilder)
*/

private void initializeGUI()
{
dataToXlsPanel = new ExtractBomPanel();

// =======================================================
// most everything here is auto generated by JBuilder
// =======================================================

ok.setHorizontalTextPosition( SwingConstants.CENTER );
ok.setText( "OK" );
ok.addActionListener( new java.awt.event.ActionListener()
{
public void actionPerformed( ActionEvent e )
{
ok_actionPerformed( e );
}
} );
cancel.setHorizontalTextPosition( SwingConstants.CENTER );
cancel.setText( "Cancel" );
cancel.addActionListener( new java.awt.event.ActionListener()
{
public void actionPerformed( ActionEvent e )
{
cancel_actionPerformed( e );
}
} );

// =======================================================
// Here we get a static string from the registry to
// display as the dialog title
// =======================================================

this.setTitle( "Data to Excel" );
dataToXlsPanel.setMaximumSize( new Dimension( 500 , 150 ) );
dataToXlsPanel.setMinimumSize( new Dimension( 500 , 150 ) );
dataToXlsPanel.setPreferredSize( new Dimension( 500 , 150 ) );
dataToXlsPanel.setToolTipText( "" );
buttonPanel.setMaximumSize( new Dimension( 500 , 50 ) );
buttonPanel.setMinimumSize( new Dimension( 500 , 50 ) );
buttonPanel.setPreferredSize( new Dimension( 500 , 50 ) );
cancel.setHorizontalTextPosition( SwingConstants.CENTER );
cancel.setText( "Cancel" );
this.getContentPane().add( dataToXlsPanel , BorderLayout.CENTER );
this.getContentPane().add( buttonPanel , java.awt.BorderLayout.SOUTH );
buttonPanel.add( ok , null );
buttonPanel.add( cancel );

}

/**
* Processes the OK button getting pushed
*
* @param event
* the event (not used)
*/

void ok_actionPerformed( ActionEvent event )
{
//this.dispose();
startCreateOperation ();
setVisible(false);
dispose();
}

/**
* Processes the OK button getting pushed
*
* @param event
* the event (not used)
*/

void cancel_actionPerformed( ActionEvent event )
{
this.dispose();
isOk = false;
setVisible(false);

}

public boolean getIsOk()
{
return isOk;
}

public String getFilespec()
{
String s = dataToXlsPanel.getFilespec();
if( s.endsWith( ".xls" ) )
return s;
else
return s + ".xls";
}


private void startCreateOperation()
{

String debu=getFilespec();
JOptionPane.showMessageDialog(new JFrame(),"The target xls file name is:" + getFilespec() ,"Alert",JOptionPane.ERROR_MESSAGE);
////try
////{
JOptionPane.showMessageDialog(new JFrame(),"Going to call ExtractBomOperation constructor","Alert",JOptionPane.ERROR_MESSAGE);
oper=new ExtractBomOperation(session, desktop,debu,bom_line);
////}
////catch(TCException ex)
////{
//ex.getError();
//JOptionPane.showMessageDialog(new JFrame(),"The Error while calling AMATExtractBomOperation constructor is:" + ex.getError(),"Alert",JOptionPane.ERROR_MESSAGE);
////}
//oper=new AMATExtractBomOperation();

JOptionPane.showMessageDialog(new JFrame(),"Finished calling ExtractBomOperation constructor","Alert",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(),"Calling executeOperation method ","Alert",JOptionPane.ERROR_MESSAGE);
oper.executeOperation();
JOptionPane.showMessageDialog(new JFrame(),"End of executeOperation method ","Alert",JOptionPane.ERROR_MESSAGE);
}

public void startOperation ( String startMessage )
{
// Define the body or what needs to be done before this opereation commences
}
public void endOperation ( )
{


}


public void run ()
{
setVisible(true);
setEnabled(true);
//setModal(true);
}


}

/* End code for ExtractBomDialog class*/


/* Begin code for ExtractBomOperation class */


package com.teamcenter.project.rac.tcapps.pse.commands.extractbom;

//imports
//import com.ugsolutions.aif.*;
//import com.ugsolutions.iman.kernel.*;
import com.teamcenter.rac.util.*;

import com.teamcenter.rac.aif.*;
import com.teamcenter.rac.aif.kernel.*;
import com.teamcenter.rac.kernel.*;
//import com.teamcenter.rac.util.*;
//import com.teamcenter.pune.rac.tcapps.pse.extractbom.utils.*;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.util.Date;
import java.text.Format;
import java.text.SimpleDateFormat;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import javax.swing.filechooser.*;
import java.io.*;
import javax.swing.filechooser.*;
import java.util.*;




public class ExtractBomOperation //extends AbstractAIFOperation
{
public TCSession session =null;
public AIFDesktop desktop =null;
public TCComponentBOMLine ctx = null ; // = null;
//private TCComponentBOMLine bom_line; //= null;
//private TCComponent comp ; //= null ;
public int currentRow = 0;
public String fileName = null;
public HSSFRow titlerow = null;
public HSSFCellStyle styleShaded = null;
public HSSFCellStyle styleNormal = null;
public HSSFCellStyle styleHeader = null;

public HSSFWorkbook wb = null;
public FileOutputStream fileOut = null;
public HSSFSheet sheet = null;

public final static int DATE_COL = 0;
public final static int ITEM_COL = 1;
public final static int REV_COL = 2;
public final static int NAME_COL = 3;
public final static int OWNER_COL = 4;
public final static int GROUP_COL = 5;
public final static int RELSTAT_COL = 6;
public final static int TYPE_COL = 7;
public final static int UOM_COL = 8;

public final static String DATE_DESC = "Creation Date";
public final static String ITEM_DESC = "Item Id";
public final static String REV_DESC = "Rev";
public final static String NAME_DESC = "Name";
public final static String OWNER_DESC = "Owner";
public final static String GROUP_DESC = "Owning Group";
public final static String RELSTAT_DESC = "Status(es)";
public final static String UOM_DESC = "UOM";
public final static String TYPE_DESC = "Item Type";

public final static short DATE_WID = 12;
public final static short OWNER_WID = 15;
public final static short GROUP_WID = 15;
public final static short UOM_WID = 5;
public final static short ITEM_WID = 32;
public final static short REV_WID = 4;
public final static short NAME_WID = 32;
public final static short RELSTAT_WID = 10;
public final static short TYPE_WID = 20;


/**
* Constructs the operation. The object is added to the set, any children are gathered and then
* they are added too.
*
* @param fn
* the file name
* @param c
* the component array
*/

public ExtractBomOperation( TCSession theSession, AIFDesktop dt,String fn , TCComponentBOMLine bl)
{
super();
//if(this!=null)
session = theSession;
desktop = dt;
JOptionPane.showMessageDialog(new JFrame(),"Inside ExtractBomOperation constructor","Alert",JOptionPane.ERROR_MESSAGE);
// else
//JOptionPane.showMessageDialog(new JFrame(),"Not Inside AMATExtractBomOperation constructor as is null","Alert",JOptionPane.ERROR_MESSAGE);
fileName = fn;
ctx = bl;
JOptionPane.showMessageDialog(new JFrame(),"End of ExtractBomOperation constructor","Alert",JOptionPane.ERROR_MESSAGE);
//flatprocess();
//executeOperation();

}
public ExtractBomOperation()
{
//super();
JOptionPane.showMessageDialog(new JFrame(),"Inside Empty ExtractBomOperation constructor","Alert",JOptionPane.ERROR_MESSAGE);
}

/**
* Executes the operation.
*/

public void executeOperation()
{
JOptionPane.showMessageDialog(new JFrame(),"Inside executeOperation","Alert",JOptionPane.ERROR_MESSAGE);
HSSFFont fontBold = null;
HSSFFont fontNormal = null;
try
{
JOptionPane.showMessageDialog(new JFrame(),"Inside try block of executeOperation","Alert",JOptionPane.ERROR_MESSAGE);
wb = new HSSFWorkbook();
JOptionPane.showMessageDialog(new JFrame(),"Completed instantiation of HSSFWORKBOOK","Alert",JOptionPane.ERROR_MESSAGE);
////fileOut = new FileOutputStream( fileName );
JOptionPane.showMessageDialog(new JFrame(),"Completed mentioning the output xls file name","Alert",JOptionPane.ERROR_MESSAGE);
sheet = wb.createSheet("PSE BOM");
JOptionPane.showMessageDialog(new JFrame(),"Completed creating sheets for the workbook","Alert",JOptionPane.ERROR_MESSAGE);
// Create fonts
JOptionPane.showMessageDialog(new JFrame(),"Starting creation of fonts","Alert",JOptionPane.ERROR_MESSAGE);
fontBold = wb.createFont();
fontBold.setFontHeightInPoints( (short) 10 );
fontBold.setFontName( "Times New Roman" );
fontBold.setBoldweight( HSSFFont.BOLDWEIGHT_BOLD );
fontNormal = wb.createFont();
fontNormal.setFontHeightInPoints( (short) 10 );
fontNormal.setFontName( "Times New Roman" );
fontNormal.setBoldweight( HSSFFont.BOLDWEIGHT_NORMAL );
JOptionPane.showMessageDialog(new JFrame(),"Completed creation of fonts","Alert",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(),"Starting creation of Cell Style","Alert",JOptionPane.ERROR_MESSAGE);
styleNormal = wb.createCellStyle();
styleNormal.setFont( fontNormal );
styleNormal.setAlignment( HSSFCellStyle.ALIGN_LEFT );

styleShaded = wb.createCellStyle();
styleShaded.setFont( fontNormal );
styleShaded.setAlignment( HSSFCellStyle.ALIGN_LEFT );
styleShaded.setFillForegroundColor( HSSFColor.LIGHT_TURQUOISE.index );
styleShaded.setFillPattern( HSSFCellStyle.SOLID_FOREGROUND );

styleHeader = wb.createCellStyle();
styleHeader.setFont( fontBold );
styleHeader.setAlignment( HSSFCellStyle.ALIGN_CENTER );
styleHeader.setBorderBottom( HSSFCellStyle.BORDER_MEDIUM );
JOptionPane.showMessageDialog(new JFrame(),"Completed creation of Cell Style","Alert",JOptionPane.ERROR_MESSAGE);
titlerow = newRow();
JOptionPane.showMessageDialog(new JFrame(),"Finished instantiating newRow","Alert",JOptionPane.ERROR_MESSAGE);
//newTitleCell( titlerow , DATE_COL , DATE_WID , DATE_DESC );
JOptionPane.showMessageDialog(new JFrame(),"Starting setting the title row in xls file","Alert",JOptionPane.ERROR_MESSAGE);
newTitleCell( titlerow , ITEM_COL , ITEM_WID , ITEM_DESC );
newTitleCell( titlerow , REV_COL , REV_WID , REV_DESC );
newTitleCell( titlerow , NAME_COL , NAME_WID , NAME_DESC );
//newTitleCell( titlerow , OWNER_COL , OWNER_WID , OWNER_DESC );
//newTitleCell( titlerow , GROUP_COL , GROUP_WID , GROUP_DESC );
//newTitleCell( titlerow , RELSTAT_COL , RELSTAT_WID , RELSTAT_DESC );
//newTitleCell( titlerow , UOM_COL , UOM_WID , UOM_DESC );
newTitleCell( titlerow , TYPE_COL , TYPE_WID , TYPE_DESC );
JOptionPane.showMessageDialog(new JFrame(),"Finished setting the title row in xls file","Alert",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(),"Going to traverse the bomline components for writing in xls file","Alert",JOptionPane.ERROR_MESSAGE);
/////traverse();
JOptionPane.showMessageDialog(new JFrame(),"Finished traversing the bomline components for writing in xls file","Alert",JOptionPane.ERROR_MESSAGE);
////wb.write( fileOut );
////fileOut.close();

MessageBox.post( fileName + "\nExcel File created." , "Success" , MessageBox.INFORMATION );
}catch(Exception ex)
{
ex.printStackTrace();
MessageBox.post( ex );
//JOptionPane.showMessageDialog(new JFrame(),"The Following Error occured:"+ ex.toString(),"Alert",JOptionPane.ERROR_MESSAGE);
}
}

public void traverse() throws Exception
{

AIFComponentContext[] aifChildCompArr = ctx.getChildren();
int chcount = aifChildCompArr.length;
for( int i = 0 ; i < chcount ; i++ )
{
TCComponentBOMLine chBomLine = (TCComponentBOMLine) aifChildCompArr[i]
.getComponent();
write( chBomLine , i );
}
return;
}


//
// Change History

//
public void write( TCComponentBOMLine bline , int i ) throws Exception
{
currentRow = i;
//Format formatter = new SimpleDateFormat( "d-MMM-yyyy" );

TCComponentBOMLine rev = bline;
boolean shaded = (i % 2 != 0);
//IMANComponentItem item = rev.getItem();
String itemType = null;
//Date date = null;

HSSFRow theRow = null;
HSSFCell theCell = null;
//IMANProperty prop = null;
theRow = newRow();

//
// add the Date created
//

/* theCell = newNormalCell( theRow , DATE_COL , shaded );
date = rev.getDateProperty( "creation_date" );

theCell.setCellValue( formatter.format( date ) );
if( MyApp.SPEW ) System.out.println( "Date: " + rev.getDateProperty( "creation_date" ) );*/

//
// add the item id
//

theCell = newNormalCell( theRow , ITEM_COL , shaded );
theCell.setCellValue( rev.getTCProperty( "bl_item_item_id" ).getStringValue() );
//if( MyApp.SPEW ) System.out.println( "Item: " + item.getIMANProperty( "item_id" ).getStringValue() );

//
// add the rev id
//

theCell = newNormalCell( theRow , REV_COL , shaded );
theCell.setCellValue( rev.getTCProperty( "item_revision_id" ).getStringValue() );
//if( MyApp.SPEW ) System.out.println( "Rev: " + rev.getIMANProperty( "item_revision_id" ).getStringValue() );

//
// add the name
//

theCell = newNormalCell( theRow , NAME_COL , shaded );
theCell.setCellValue( rev.getTCProperty( "bl_item_object_name" ).getStringValue() );
//if( MyApp.SPEW ) System.out.println( "Name: " + rev.getIMANProperty( "object_name" ).getStringValue() );

//
// add the owning user
//

/*theCell = newNormalCell( theRow , OWNER_COL , shaded );
IMANComponentPerson person = (IMANComponentPerson) rev.getReferenceProperty( "owning_user" )
.getReferenceProperty( "person" );
if( MyApp.SPEW ) System.out.println( "Owner: " + person );

theCell.setCellValue( person.toString() );

//
// add the owning group
//

theCell = newNormalCell( theRow , GROUP_COL , shaded );
IMANComponentGroup group = (IMANComponentGroup) rev.getReferenceProperty( "owning_group" );
theCell.setCellValue( group.toString() );
if( MyApp.SPEW ) System.out.println( "Owning Group: " + group.toString() );*/

//
// add the Item Type
//

theCell = newNormalCell( theRow , TYPE_COL , shaded );
itemType = rev.getTCProperty( "bl_item_object_desc" ).getStringValue();
theCell.setCellValue( itemType );
//if( MyApp.SPEW ) System.out.println( "Type: " + item.getIMANProperty( "object_type" ).getStringValue() );

//
// get the Unit of Measure
//

/*prop = item.getIMANProperty( "uom_tag" );
theCell = newNormalCell( theRow , UOM_COL , shaded );

if( null != prop )
{
IMANComponent comp = prop.getReferenceValue();
if( null != comp )
{
if( MyApp.SPEW ) System.out.println( "UOM: " + comp.getProperty( "symbol" ) );
theCell.setCellValue( comp.getProperty( "symbol" ) );
}
}*/

//
// add the release statuses
//

/* theCell = newNormalCell( theRow , RELSTAT_COL , shaded );
theCell.setCellValue( rev.getProperty( "release_status_list" ) );
if( MyApp.SPEW ) System.out.println( "Statuses: " + rev.getProperty( "release_status_list" ) );*/

return;

}

public HSSFRow newRow()
{
return sheet.createRow( currentRow++ );
}

public HSSFCell newNormalCell( HSSFRow row , int col , boolean shaded )
{
HSSFCell cell = row.createCell( (short) col );
cell.setCellType( HSSFCell.CELL_TYPE_STRING );

if( shaded )
{
cell.setCellStyle( styleShaded );
}
else
{
cell.setCellStyle( styleNormal );
}

cell.setCellValue( "" );

return cell;
}

public HSSFCell newNumberCell( HSSFRow row , int col , boolean shaded )
{
HSSFCell cell = row.createCell( (short) col );
cell.setCellType( HSSFCell.CELL_TYPE_NUMERIC );

if( shaded )
{
cell.setCellStyle( styleShaded );
}
else
{
cell.setCellStyle( styleNormal );
}

return cell;
}

public HSSFCell newBooleanCell( HSSFRow row , int col , boolean shaded )
{
HSSFCell cell = row.createCell( (short) col );
cell.setCellType( HSSFCell.CELL_TYPE_BOOLEAN );

if( shaded )
{
cell.setCellStyle( styleShaded );
}
else
{
cell.setCellStyle( styleNormal );
}

return cell;
}

public void newTitleCell( HSSFRow row , int col , int wid , String val )
{
HSSFCell cell = row.createCell( (short) col );
cell.setCellStyle( styleHeader );
cell.setCellType( HSSFCell.CELL_TYPE_STRING );
cell.setCellValue( val );
sheet.setColumnWidth( (short) col , (short) (wid * 256) );
}
}


/* end of ExtractBomOperation class */
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2009
Added on Sep 2 2008
5 comments
745 views