Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-boot Test to load external jars (equivalent of loader.path)

We have an application which has runtime dependencies on external jars (e.g Talend jobs running within Spring-boot). Now we're able to get this launched from Spring-Boot using the -Dloader.path argument. However, we're unable to run integration-test using the external lib folder (i.e launch Talend jobs from Spring-Boot Test). Is it possible to have a similar option to load external jobs for integration-tests using SpringBoot test?

like image 724
Jebuselwyn Martin Avatar asked Nov 07 '22 00:11

Jebuselwyn Martin


1 Answers

I got this sorted.

Intellij -> Select Module -> Open Module Setting -> Dependency -> Add Dependency -> select the external jar -> Scope to be test only.

This way it is working fine for test case and at the same time not being used in actual main code.

Where to keep the jar ?

Given its going to be used in test cases, I would suggest commit the jar in src/test/lib and select this path while adding dependency.

Intellij generate the .iml file(which has a list of dependency) if you commit the same in your repo then other team member can easily use without any further setup.

Now question remains for linux env or CIT environment. I think we could add this jar via CLASSPATH env variable and then starting any CIT jobs.

Mix of solution but then its working as expected for me.

One more solution : Install the external jar in local repo and add dependency in pom.xml with test scope. Easy option it is.

Installing jar on local repo :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>3.0.0-M1</version>
    <executions>
        <execution>
            <id>install-jar</id>
            <phase>initialize</phase>
            <goals>
                <goal>install-file</goal>
            </goals>
            <configuration>
                <file>${project.basedir}/src/test/lib/somejar-1.0.jar</file>
                <groupId>com.beta.gamma</groupId>
                <artifactId>somejar</artifactId>
                <version>1.0</version>
                <packaging>jar</packaging>
            </configuration>
        </execution>
    <executions>
</plugin>

Now same can be added as dependency as other dependency. This will work on environments.

like image 66
bittu Avatar answered Nov 26 '22 03:11

bittu