In order to avoid code duplication, I decided to pack some classes in the spring based library project. Below are the steps I took:
- Created project using spring initialzr.
- Created desired structure and add classes.
- Deleted main class
- Added to
pom.xml
required dependencies - Added to
pom.xml
pluginmaven-jar-plugin
- Created simple script to automate packaging and installing dependency to my local maven repository:
#!/usr/bin/env bash
POM="pom.xml"
ARTIFACT="springbot-messenger-client"
MVN_VERSION=$(mvn -q -f $POM \
-Dexec.executable=echo \
-Dexec.args='${project.version}' \
--non-recursive \
exec:exec)
mvn package -f $POM
mvn install:install-file \
-Dfile="target/"$ARTIFACT"-"$MVN_VERSION".jar" \
-DgroupId=ai.optime \
-DartifactId=$ARTIFACT \
-Dversion=$MVN_VERSION \
-Dpackaging=jar
echo "Version "$MVN_VERSION" of "$ARTIFACT" installed"
- Script execution succeeded and I've added my newly created dependency to another project.
During application startup, I've got an exception:
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.dataformat.yaml.YAMLFactory
Class YAMLFactory
belongs to dependency jackson-dataformat-yaml
which is added to pom.xml
of library project:
From my understanding, mvn package
does not include dependencies, so how to include them properly ? I know the concept of fat jar but this is probably not the right solution.