Maven – Little Big Extra http://littlebigextra.com A technology blog covering topics on Java, Scala, Docker, AWS, BigData, DevOps and much more to come. Do it yourself instructions for complex to simple problems for a novice to an expert. Sun, 14 Oct 2018 14:37:12 +0000 en-US hourly 1 https://wordpress.org/?v=4.8.7 http://littlebigextra.com/wp-content/uploads/2023/04/cropped-logo-32x32.png Maven – Little Big Extra http://littlebigextra.com 32 32 How to convert JSON schema to Java classes using maven plugin http://littlebigextra.com/how-to-convert-json-schema-to-java-classes-using-maven-plugin/ http://littlebigextra.com/how-to-convert-json-schema-to-java-classes-using-maven-plugin/#comments Tue, 09 May 2023 14:59:48 +0000 http://littlebigextra.com/?p=971 Convert JSON schema to Java classes using maven plugin Introduction We often need to convert JSON schema’s to Java classes, there is a jsonschema2pojo-maven-plugin which helps in generating POJO(plain old java objects) from JSON or JSON schema. To use it all we need is add this plugin, update dependencies and run mvn generate Add jsonschema2pojo-maven-plugin […]

The post How to convert JSON schema to Java classes using maven plugin appeared first on Little Big Extra.

]]>
Share this article on

Convert JSON schema to Java classes using maven plugin

Introduction

We often need to convert JSON schema’s to Java classes, there is a jsonschema2pojo-maven-plugin which helps in generating POJO(plain old java objects) from JSON or JSON schema.

To use it all we need is add this plugin, update dependencies and run mvn generate

Add jsonschema2pojo-maven-plugin in POM.XML

Add this plugin to your POM.XML under plugin section

<plugin>
				<groupId>org.jsonschema2pojo</groupId>
				<artifactId>jsonschema2pojo-maven-plugin</artifactId>
				<version>0.4.34</version>
				<configuration>
					<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
					<targetPackage>com.test.gen</targetPackage>
					<useCommonsLang3>true</useCommonsLang3>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>generate</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

Add Maven dependencies

The generated types depend on Commons Lang library for equals, hashCode and toString. Also, you need to add Jackson-databind which contains the data-binding functionality and tree-model for Jackson Data Processor, this jar has a transitive dependency on jackson-core and jackson-annotations so they will be downloaded automatically.

<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.0</version>
		</dependency>
		
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>

 

Run the Maven Goal

You can run

mvn generate-sources
goal to generate the java classes. All files will be added in the target/java-gen folder by default
If you need it to be generated in another folder you can make use of
${basedir}/src/main/gen

however I have noticed that specifying any other folder doesn’t add that folder automatically as source folder in eclipse, so you might see some compilation errors.

Make sure that generated folder is added as a source folder in your IDE (Properties ->Java build Path -> Add source folder in eclipse).

Generating classes from JSON and not from schema

If you want to generate Java classes from JSON rather than JSON schema add

<sourceType>json</sourceType>

inside the configuration tag as default source type is JSON Schema.

The post How to convert JSON schema to Java classes using maven plugin appeared first on Little Big Extra.

]]>
http://littlebigextra.com/how-to-convert-json-schema-to-java-classes-using-maven-plugin/feed/ 4
How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin http://littlebigextra.com/push-docker-images-docker-hub-using-maven/ http://littlebigextra.com/push-docker-images-docker-hub-using-maven/#comments Sat, 25 Mar 2023 12:15:07 +0000 http://littlebigextra.com/?p=501 Push a Docker image to DockerHub using docker maven plugin fabric8.io   Introduction If you want to push a docker image to Docker Hub repository, it can be achieved using docker maven plugin from fabric8.io. This plugin lets you build images, start and stop containers and push it to Docker repositories In case you are wondering […]

The post How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin appeared first on Little Big Extra.

]]>
Share this article on

Push a Docker image to DockerHub using docker maven plugin fabric8.io

 

Introduction

If you want to push a docker image to Docker Hub repository, it can be achieved using docker maven plugin from fabric8.io. This plugin lets you build images, start and stop containers and push it to Docker repositories

In case you are wondering the difference between a container and image, please note that in docker terminology a running image is called container.
In this tutorial, we are going to

  • Build a docker image
  • Push image to Docker Hub repository

&nsbp;

Want to build a docker image first using this plugin ?
Read Here : How to Build a Docker Image and start stop container
  1. For the below example, I have used Spring Boot Rest service project which is connected to MongoDB. See below link for reference.
  2. Using io.fabric8 plugin, under the plugin section add the io.fabric8 plugin
    <plugin>
    	<groupId>io.fabric8</groupId>
    	<artifactId>docker-maven-plugin</artifactId>
    	<version>0.20.0</version>....

  3. We need to first build the image from Dockerfile, this plugin supports all the command which are in Dockerfile and you can directly create a docker image by giving arguments in pom.xml but In my view making docker images from Docker file is much easier and simpler. So we will ask maven plugin in below step to look for Dockerfile in root( project base directory)
    <name>springboot-mongo-dockerimage:${project.version}</name>
        <alias>springboot-mongo-dockerimage</alias>
    <build>
        <dockerFileDir>${project.basedir}</dockerFileDir>
    </build>
  4. Next we specify the docker registry address
    <registry>registry.hub.docker.com/YOUR_DOCKER_HUB_USERNAME</registry>
  5. Now we need to add authentication credentials in <authconfig> tag
    <authConfig>
    	<username>ENTER YOUR DOCKER HUB USERNAME LIKE abhishek</username>
    	<password>ENTER YOUR DOCKER HUB PASSWORD</password>
    </authConfig>
  6. We will add execution phases, where we will push the image
    <execution>
    	<id>push</id>
    	<phase>post-integration-test</phase>
    	<goals>
    		<goal>push</goal>
    	</goals>
    </execution>
  7. Now run the pom.xml using mvn clean install and check your docker hub repo after some time to see if image has been pushed. If you are pushing the image for first time its gonna take some time  depending on the size of image.

Here is the complete build section from the plugin, hope this help.

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>io.fabric8</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.20.0</version>
				<configuration>
					<registry>registry.hub.docker.com/YOUR_DOCKER_HUB_USERNAME</registry>

					<images>
						<image>
							<name>springboot-mongo-dockerhub:${project.version}</name>
							<alias>springboot-mongo-dockerhub</alias>
							<build>
								<dockerFileDir>${project.basedir}</dockerFileDir>

							</build>
							<run>
								<namingStrategy>alias</namingStrategy>
								<dependsOn>
									<container>mongo</container>
								</dependsOn>

								<links>
									<link>mongo</link>
								</links>
								<ports>
									<port>9876:8080</port>
								</ports>
								<log>
									<prefix>TC</prefix>
									<date>default</date>
									<color>cyan</color>
								</log>
							</run>
						</image>
					</images>
					<authConfig>
						<username>ENTER YOUR DOCKER HUB USERNAME LIKE abhishek</username>
						<password>ENTER YOUR DOCKER HUB PASSWORD</password>
					</authConfig>
				</configuration>

				<executions>
					<execution>
						<id>start</id>
						<phase>pre-integration-test</phase>
						<goals>
							<goal>stop</goal>
							<goal>build</goal>
							<goal>start</goal>
						</goals>
					</execution>
					<execution>
						<id>push</id>
						<phase>post-integration-test</phase>
						<goals>
							<goal>stop</goal>
							<goal>push</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

 

 

If you get an error : io.fabric8:docker-maven-plugin:0.20.0:build failed: A tar file cannot include itself

How to fix- A tar file cannot include itself

The post How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin appeared first on Little Big Extra.

]]>
http://littlebigextra.com/push-docker-images-docker-hub-using-maven/feed/ 2
How to add remote archetype catalog in Eclipse http://littlebigextra.com/how-to-add-remote-archetype-catalog-in-eclipse/ http://littlebigextra.com/how-to-add-remote-archetype-catalog-in-eclipse/#respond Fri, 24 Feb 2023 17:03:27 +0000 http://52.37.230.57/?p=252 Add Maven Remote catalogue in eclipse Maven remote catalogues are very useful in starting a project quickly and neatly. The project structure including src, test directory are created along with pom dependencies. Follow below steps to add remote archetype catalogue Go to Windows -> Preferences -> Maven ->Archetype Click on Add Remote Catalog Add catalogue […]

The post How to add remote archetype catalog in Eclipse appeared first on Little Big Extra.

]]>
Share this article on

Add Maven Remote catalogue in eclipse

Maven remote catalogues are very useful in starting a project quickly and neatly. The project structure including src, test directory are created along with pom dependencies.

Follow below steps to add remote archetype catalogue

  1. Go to Windows -> Preferences -> Maven ->Archetype
  2. Click on Add Remote Catalog
    Remote Maven archetype
  3. Add catalogue file as
    • http://repo1.maven.org/maven2/archetype-catalog.xml
  4. Description as
    • Remote Archetype catalogue
  5. Click on Verify, you should see a message like Found XXX archetype’s

If you are behind a proxy you might need to go to Windows -> Preference-> Network and add the proxy details

Why not use this remote archetype to create your first Spring Boot Project

Follow this Video for more details

The post How to add remote archetype catalog in Eclipse appeared first on Little Big Extra.

]]>
http://littlebigextra.com/how-to-add-remote-archetype-catalog-in-eclipse/feed/ 0