spring - Storing base java project inside child project jar (maven, docker) -
thanks having @ this! max
in future i'm going building lots of microservices based upon same parent java project. these microservices going using spring cloud , docker. have base java project , child project. main each microservices should inherited parent project. till i've been using
mvn clean package assembly:single
for building jar microservice parent store inside jar. run
java -cp microservice.jar path.to.parent.main
which working fine. i'm sure it's not best way go , i'd love advice improvements.
my problem want use docker:build
mvn clean package docker:build
after packaging microservice using docker:build, how specify path parent project's main since parent project no longer being stored in jar made docker:build
.
microservice (child)
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>0.0.1</modelversion> <groupid>com.example</groupid> <artifactid>micro-service</artifactid> <version>0.0.1-snapshot</version> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.3.3.release</version> <relativepath /> <!-- lookup parent repository --> </parent> <repositories> <repository> <id>spring-snapshots</id> <name>spring snapshots</name> <url>http://repo.spring.io/libs-snapshot-local</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>spring milestones</name> <url>http://repo.spring.io/libs-milestone-local</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>spring-releases</id> <name>spring releases</name> <url>http://repo.spring.io/libs-release-local</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>repository.springframework.maven.release</id> <name>spring framework maven release repository</name> <url>http://maven.springframework.org/release</url> </repository> </repositories> <build> <plugins> <plugin> <artifactid>maven-assembly-plugin</artifactid> <configuration> <descriptorrefs> <descriptorref>jar-with-dependencies</descriptorref> </descriptorrefs> </configuration> </plugin> <plugin> <groupid>com.spotify</groupid> <artifactid>docker-maven-plugin</artifactid> <version>0.4.10</version> <configuration> <imagename>example</imagename> <baseimage>java</baseimage> <entrypoint>["java", "-jar", "/${project.build.finalname}.jar"]</entrypoint> <!-- copy service's jar file target root directory of image --> <resources> <resource> <targetpath>/</targetpath> <directory>${project.build.directory}</directory> <include>${project.build.finalname}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build> <dependencies> . <!-- removed other dependancies save space --> . <dependency> <groupid>com.example</groupid> <artifactid>parent-service</artifactid> <version>0.0.1-snapshot</version> </dependency> </dependencies> <dependencymanagement> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-parent</artifactid> <version>brixton.build-snapshot</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagement> </project>
https://github.com/spotify/docker-maven-plugin
http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html
solved
thanks @m. deinum comment.
i changed pom.xml to
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>0.0.1</modelversion> <groupid>com.example</groupid> <artifactid>micro-service</artifactid> <version>0.0.1-snapshot</version> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.3.3.release</version> <relativepath /> <!-- lookup parent repository --> </parent> <repositories> <repository> <id>spring-snapshots</id> <name>spring snapshots</name> <url>http://repo.spring.io/libs-snapshot-local</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>spring milestones</name> <url>http://repo.spring.io/libs-milestone-local</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>spring-releases</id> <name>spring releases</name> <url>http://repo.spring.io/libs-release-local</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>repository.springframework.maven.release</id> <name>spring framework maven release repository</name> <url>http://maven.springframework.org/release</url> </repository> </repositories> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <version>1.3.6.release</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> . <!-- removed other dependancies save space --> . <dependency> <groupid>com.example</groupid> <artifactid>parent-service</artifactid> <version>0.0.1-snapshot</version> </dependency> </dependencies> <dependencymanagement> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-parent</artifactid> <version>brixton.build-snapshot</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagement> </project>
i run
mvn clean package
Comments
Post a Comment