0

I have spring boot project which is packaged into jar. I have external jar(Jasper) add into pom like below

<dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>${jasperreports.version}</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jasperreports-6.13.0.jar</systemPath>
    </dependency>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install-jasperreports613</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${project.basedir}/lib/jasperreports-6.13.0.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>net.sf.jasperreports</groupId>
                            <artifactId>jasperreports</artifactId>
                            <version>6.13.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin>

        </plugins>
    </build>

When run jar (java -jar myapp.jar) i am gettig classdefNotfound for jasper.

Caused by: java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRDataSource
        at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_202]
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[na:1.8.0_202]
        at java.lang.Class.getDeclaredMethods(Unknown Source) ~[na:1.8.0_202]
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
        ... 29 common frames omitted
Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRDataSource
        at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_202]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_202]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) ~[e-statement-core-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_202]
        ... 33 common frames omitted
    
    

When i extracted the package and there is no jasper lib is included in package. How to include the external libraries into package.

4
  • The reason I have added it as external is that the access is restrcited in network level. Commented Oct 9, 2020 at 8:36
  • So you are inside a company network? Does your company have a Nexus or Artifactory server? Commented Oct 9, 2020 at 9:39
  • Yes correct . We do have have nexus repository but for current project not supposed to use bcs should run as stand alone jar in Linux server . So I was trying to find if there is a way apart from using repository and include external lib within the application package. Commented Oct 9, 2020 at 9:44
  • The way to do this is as follows: You build your project with the help Nexus (this will hopefully also serve you jasperreports). To build an executable jar, you use the Maven shade plugin or the Maven assembly plugin in your POM. The resulting jar will then include the dependencies, also those from Nexus. You don't need any systemPath or install-file for that. Commented Oct 9, 2020 at 10:35

1 Answer 1

1

The jar jasperreports is on MavenCentral. So if you have internet access, there is no need to handle that manually.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.