For the sake of simplicity, let's say that I have a class named "Dog".
Then I have two separated applications containing implementations of that class.
Both applications require the Dog class, hence it would be duplicated.
Now let's say for a moment that:
I'm using Spring Boot, if that info helps somehow.
As @Slaw says you can create a jar/library then use any build tool like maven or gradle and package the jar/library in your archive file when it is built and here is a link for more info https://christianlydemann.com/a-guide-to-sharing-code-between-projects/