1

I trying to create some code with PHPJasper, but at same line I get error. I think it's problems with Java SE versions.

File hello_world.jasper is already exist in my project.

Source code:

require __DIR__ . '/vendor/autoload.php';

use PHPJasper\PHPJasper;

$jasper = new PHPJasper;

$input = __DIR__ . '/vendor/geekcom/phpjasper/examples/hello_world.jasper';
$output = __DIR__ . '/vendor/geekcom/phpjasper/examples';
$options = [
    'format' => ['pdf', 'rtf']
];

$jasper->process(
    $input,
    $output,
    $options
)->execute();

var_dump($jasper);

Error in console for line with execute():

Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
    at de.cenote.tools.classpath.ApplicationClasspath.add(ApplicationClasspath.java:75)
    at de.cenote.tools.classpath.ApplicationClasspath.add(ApplicationClasspath.java:65)
    at de.cenote.tools.classpath.ApplicationClasspath.addJars(ApplicationClasspath.java:134)
    at de.cenote.tools.classpath.ApplicationClasspath.addJarsRelative(ApplicationClasspath.java:151)
    at de.cenote.jasperstarter.App.processReport(App.java:178)
    at de.cenote.jasperstarter.App.main(App.java:109)
PHP Fatal error:  Uncaught PHPJasper\Exception\ErrorCommandExecutable: Your report has an error and couldn 't be processed!\ Try to output the command using the function `output();` and run it manually in the console. in /home/jack/PhpstormProjects/JasperTest/vendor/geekcom/phpjasper/src/PHPJasper.php:219

Java version:

java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu219.04)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu219.04, mixed mode, sharing)

How can I fix it?

2
  • 1
    Yeah I would try with version <=8 it's trying to cast as URLClassLoader which works in version 8 or less. Commented Aug 19, 2019 at 13:50
  • Base ClassLoader No Longer from URLClassLoader Commented Aug 19, 2019 at 18:37

1 Answer 1

0

I have a solution of this problem.

I remove all java packages (sudo apt-get remove openjdk...) and install again with version Java JDK 1.8 (instruction for ubuntu)

After this I got correct version of Java:

java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

And I don't have errors in my project

Sign up to request clarification or add additional context in comments.

1 Comment

I use java version "1.8.0_391" on windows and I have the same error using jasperstarter. Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.