https://bugs.documentfoundation.org/show_bug.cgi?id=145526

            Bug ID: 145526
           Summary: NoClassDefFound Error in Java Macro when trying to
                    load another class
           Product: LibreOffice
           Version: 7.1.6.2 release
          Hardware: x86-64 (AMD64)
                OS: Windows (All)
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Writer
          Assignee: libreoffice-bugs@lists.freedesktop.org
          Reporter: alexander.ree...@idorsia.com

Description:
When I try to execute a Java Macro which loads any other class despite the one
first loaded by the URLClassLoader, I get a NoClassDefFound Error.
I searched before filing this bug if it is already here. I could not find it,
in case I overlooked it, my apologies. 


Steps to Reproduce:
1. Go to <LOInstall Folder>\share\Scripts\java
2. Duplicate directory HelloWorld, e. g. to HelloWorldTest
3. Open the new directory, in there is HelloWorld.java
4. Adapt HelloWorld.java as follows:
package org.libreoffice.example.java_scripts;

import com.sun.star.script.provider.XScriptContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XText;
/**
 *  HelloWorld class
 *
 */
public class HelloWorld {
    public static void printHW(XScriptContext xSc) {

        // getting the text document object
        XTextDocument xtextdocument = (XTextDocument)
UnoRuntime.queryInterface(
                                          XTextDocument.class,
xSc.getDocument());
        XText xText = xtextdocument.getText();
        XTextRange xTextRange = xText.getEnd();
        xTextRange.setString("Hello World (in Java)");
        LoadMe lm = new LoadMe();  // the actual change

        xTextRange.setString("Test String: " + lm.getText());
    }// printHW

}

5. create a new java class file, LoadMe.java e. g. as follows:

package org.libreoffice.example.java_scripts;

public class LoadMe {

        public LoadMe() {

        }
         public String getText() {
                 return "Success";
         }

}

6. Compile the java files, e. g. in a dos command window after changing to the
right path:

SET OOO=c:\progra~1\LibreOffice\program\classes
SET OOOPATH=%OOO%\juh.jar;%OOO%\jurt.jar;%OOO%\ridl.jar;%OOO%\unoil.jar
javac -cp "%OOOPATH%" LoadMe.java HelloWorld.java 


7. create a new path in your current HelloWorldTest directory
all of those subfolders have to be created according to the java package name
of the created class files

org\libreoffice\example\java_scripts

8. copy the class files created by compilation to 

org\libreoffice\example\java_scripts

9. Update the jar file with the new classes, e, g.: 

jar -cvf HelloWorld.jar org

from the command window in the HelloWorldTest folder
If everything is done right, the parcel descriptor should still fit.

10. Now start Writer

11. Go to 
Tools -> Macros -> Run Macro

12. Search the available macros HelloWorldTest in the LibreOffice list and
execute it







Actual Results:
NoClassDefFoundError. I can debug until the point LoadMe is called, so
HelloWorld is executed but LoadMe is not on the classpath.

Expected Results:
LoadMe is executed and the String in Writer changes from "Hello World (in
Java)" to "Test String: Success"


Reproducible: Always


User Profile Reset: Yes



Additional Info:
The issue seems with ScriptProviderForJava.java

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to