Bug 57639 - using external jars in eclipse plug-in project - getting ClassNotFound exception for ..usermodel.XWPFDocument
Summary: using external jars in eclipse plug-in project - getting ClassNotFound except...
Status: RESOLVED MOVED
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL: http://stackoverflow.com/questions/28...
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-26 15:05 UTC by furkan
Modified: 2015-02-27 11:42 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description furkan 2015-02-26 15:05:39 UTC
I created a plug-in project. In runtime eclipse, I did set up a command and added to menu in order to convert selected IFile(docx) file to XWPFDocument which I can parse it later in other java class. However, when I try to cast IFile to XWPFDocument, I get an MethodRequestor.java/InvocationTargetException.

Exception detail: org.apache.poi.xwpf.usermodel.XWPFDocument cannot be found by eu.modelwriter.architecture.textconnectors.docx.command.ui_1.0.0.qualifier

On the other hand in my java project, which is referenced in this plugin project, this line is working properly. Same jars included in both projects.

My command handler is like below:

public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO Auto-generated method stub

    XWPFDocument document = null;
    Shell shell = HandlerUtil.getActiveShell(event);
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    IStructuredSelection selection = (IStructuredSelection) sel;

    Object firstElement = selection.getFirstElement();

    if(firstElement instanceof IFile){

        try {

            IFile ifile = (IFile) Platform.getAdapterManager().getAdapter(firstElement, IFile.class);

            if (ifile == null) {
                if (firstElement instanceof IAdaptable) {
                    ifile = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class);
                }
            }

            if (ifile != null) {

                File f = ifile.getFullPath().toFile();
                document = new XWPFDocument(new FileInputStream(f)); //throws exception
            }


        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}
Comment 1 Nick Burch 2015-02-26 15:11:51 UTC
The problematic classes seem to live under the eu.modelwriter.architecture.textconnectors namespace, which is not Apache POI. You'd be best off reporting this problem to whoever it is that produces that library
Comment 2 furkan 2015-02-27 09:12:54 UTC
I used XWPFDocument in my java project. POI libraries were working fine. the time when I want to use class inside that project from handler class in plug-in project, I get an exception. frustrating.
Comment 3 Nick Burch 2015-02-27 09:42:44 UTC
Sounds like your problem is either with how you build your project, or with the other classes you use. That's not a POI problem, so you'll need to work out which it is then ask it elsewhere, sorry
Comment 4 Dominik Stadler 2015-02-27 11:42:05 UTC
You description sounds related to OSGi classloading. It sounds like "in my java project it works", means "without OSGi it works", if that is the case I would investigate how OSGi handles third party jars here, i.e. are they in the same bundle or are correct export/import definitions defined in the bundle manifests, ...