0

I have a main Spring MVC Project and I created a SpringBoot .jar which contains the main class, a .pom file, and a class with a @Scheduler method. I need to add the SpringBoot .jar as a dependency in my main project. I have tried lots of things, but don't see any progress.

My first question is if the 2 projects need to be under the same folder. And if it matters that each project has its own repo.

My second question is if I injected it properly, what I must do so the @Scheduler to run? Does it start automatically like when I run the .jar standalone, or I need to do something? I mean when I run my main project, the main() method on my SpringBoot .jar also starts?

If yes, then I haven't imported the dependency as my project needs to. So far I tried to add it as a Profile, as a module, I added its repo on my main project .pom and as a dependency.

My Project POM:

    <dependency>
     <groupId>com.example</groupId>
     <artifactId>matomo-data-parser</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <classifier>exec</classifier>
     <scope>system</scope>
     <systemPath>${basedir}/matomo-data-parser-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>

I tried without scope and systemPath, cause when I enable those, a warning is triggered about the path. Also, most guides I read don't include them.

My .jar dependency POM:

    <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>exec</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I've done what's necessary with fat vs thin .jars so I can pass it as a dependency.

Any ideas would help me.

Thanks in advance!

Younes
  • 462
  • 7
  • 15
  • When you are using Maven do _not_ use the system scope but install it properly, either to a repository server like Maven Central or Nexus, or to your local .m2 folder using "mvn install" – Thorbjørn Ravn Andersen Feb 01 '21 at 13:04
  • Yes, I don't use them (couldn't pass them as comments in code section). I 'mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=/path/to/jar' and then 'mvn clean install' my main project. I am not sure what I need to do with the repositories though, I mean each project has its own. I need to install what on where? – user14819924 Feb 01 '21 at 13:12
  • I think you are doing this wrong. Fat jars cannot be used as maven dependencies (technical reasons, think fat jars are EXE files) so you should not repackage your dependency. – Thorbjørn Ravn Andersen Feb 01 '21 at 14:22
  • According to this question: https://stackoverflow.com/questions/40089443/how-to-add-a-dependency-to-a-spring-boot-jar-in-another-project, I create 2 jars, one of which can be inserted as a maven dependency. I have tried both by the way, and before applying this solution, I had the usual 1 .jar and still @Scheduler didn't run. I mean I tried this as a solution too. – user14819924 Feb 01 '21 at 14:31
  • Would joining the sources of the two projects physically and having the spring boot project be a maven submodule under your main application so you build them together, be an option? – Thorbjørn Ravn Andersen Feb 01 '21 at 14:34
  • Sadly no, and to be more specific I need to pass this spring boot .jar as a Profile, because main project's code is being used on multiple occasions. If I achieve to pass it as a Dependency, Profile will work too. So I started with a simple dependency injection. – user14819924 Feb 01 '21 at 14:39
  • As a profile? I think you are doing things differently here too. I would suggest opening a new question explaining the underlying problem you need to solve and ask for suggestions on how to do it in a less painful way. – Thorbjørn Ravn Andersen Feb 01 '21 at 15:15

0 Answers0