jsonschema2pojo is not creating generated java object - java

I'm trying to use jsonschema2pojo to convert the FHIR schema to a java object. If I use this example schema then the generated java classes are create just fine, but when I use this Json Schema then nothing is created and I don't see any errors to understand why its not created. Can anybody help me understand where the failure is?
My pom file
<?xml version="1.0" encoding="UTF-8"?>
<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>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DMSAdpater</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.0.2</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>com.example.types</targetPackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>
</dependencies>
The Output of my mvn compile
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.example:DMSAdpater:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. # line 13, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -----------------------< org.example:DMSAdpater >-----------------------
[INFO] Building DMSAdpater 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # DMSAdpater ---
[INFO] Deleting H:\Workspaces\HDI\Project\DMS_Adapter\target
[INFO]
[INFO] --- jsonschema2pojo-maven-plugin:1.0.2:generate (default) # DMSAdpater ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # DMSAdpater ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 11 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # DMSAdpater ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.745 s
[INFO] Finished at: 2020-07-13T12:01:07-04:00
[INFO] ------------------------------------------------------------------------

Related

How to pack properties file in jar using maven

I have been trying to pack the properties file inside my jar using Maven but no luck so far.
Project Structure:
src/main/java
All java source files
src/test/java
All test java source files
src/main/resource
All properties files. For example, application.properties
...
pom.xml
POM.XML File Contents:
<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>4.0.0</modelVersion>
<groupId>Database</groupId>
<artifactId>Executor</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>DatabaseExecutor</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.framework.version>5.2.0.RELEASE</spring.framework.version>
<spring.framework.group.id>org.springframework</spring.framework.group.id>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<fully.qualified.main.class>com.applications.App</fully.qualified.main.class>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${spring.framework.group.id}</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>${spring.framework.group.id}</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>${spring.framework.group.id}</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>${spring.framework.group.id}</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>${spring.framework.group.id}</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>12.2.0.1</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.2.0</version>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>${fully.qualified.main.class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have created a build.bat file to build the code having the below content.
#ECHO OFF
call mvn -e pre-clean
call mvn -e clean
call mvn -e compile
call mvn -e package -DskipTests
Command Prompt Logs:
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< Database:Executor >--------------------------
[INFO] Building DatabaseExecutor 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.146 s
[INFO] Finished at: 2021-02-02T19:10:26+05:30
[INFO] ------------------------------------------------------------------------
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< Database:Executor >--------------------------
[INFO] Building DatabaseExecutor 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # Executor ---
[INFO] Deleting C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.465 s
[INFO] Finished at: 2021-02-02T19:10:28+05:30
[INFO] ------------------------------------------------------------------------
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< Database:Executor >--------------------------
[INFO] Building DatabaseExecutor 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Executor ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # Executor ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.165 s
[INFO] Finished at: 2021-02-02T19:10:33+05:30
[INFO] ------------------------------------------------------------------------
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< Database:Executor >--------------------------
[INFO] Building DatabaseExecutor 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Executor ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # Executor ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Executor ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # Executor ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # Executor ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy-dependencies (copy-dependencies) # Executor ---
[INFO] Copying log4j-api-2.14.0.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\log4j-api-2.14.0.jar
[INFO] Copying log4j-core-2.14.0.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\log4j-core-2.14.0.jar
[INFO] Copying junit-3.8.1.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\junit-3.8.1.jar
[INFO] Copying spring-core-5.2.0.RELEASE.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\spring-core-5.2.0.RELEASE.jar
[INFO] Copying spring-jcl-5.2.0.RELEASE.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\spring-jcl-5.2.0.RELEASE.jar
[INFO] Copying spring-context-5.2.0.RELEASE.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\spring-context-5.2.0.RELEASE.jar
[INFO] Copying spring-aop-5.2.0.RELEASE.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\spring-aop-5.2.0.RELEASE.jar
[INFO] Copying spring-beans-5.2.0.RELEASE.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\spring-beans-5.2.0.RELEASE.jar
[INFO] Copying spring-expression-5.2.0.RELEASE.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\spring-expression-5.2.0.RELEASE.jar
[INFO] Copying ojdbc14-12.2.0.1.jar to C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\libs\ojdbc14-12.2.0.1.jar
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # Executor ---
[INFO] Building jar: C:\Users\VarunJain\Documents\Personal\DevEnv\_Setups\PracticeWorkspace\DatabaseExecutor\target\Executor-0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.292 s
[INFO] Finished at: 2021-02-02T19:10:39+05:30
[INFO] ------------------------------------------------------------------------
Though the executable jar file is getting created successfully but the properties file is missing in the jar file. I'm not sure what is the mistake here. Can somebody please point out the mistake or tell me if I missed something.
Thanks In Advance,
Varun Jain
I resolved it myself by creating the new project and copying the contents from this project to the newly created project.

jsonschema2pojo maven plugin does not generate Java classes

I'm trying to obtain the Java model for the FHIR R4 specification. To accomplish this task, I downloaded the JSON Schema and I try to use jsonschema2pojo maven plugin to generate the source code.
I create a simple Maven project and I put the JSON Schema under src/main/resources/schema. So, I defined the following pom:
<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>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>fhir-generator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>com.example.fhir</targetPackage>
<useCommonsLang3>true</useCommonsLang3>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I run the goal package I obtain the folliwing output:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for come.example:fhir-generator:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. # line 24, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building fhir-generator 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- jsonschema2pojo-maven-plugin:1.0.1:generate (default) # fhir-generator ---
[WARNING] useCommonsLang3 is deprecated. Please remove it from your config.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # fhir-generator ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # fhir-generator ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # fhir-generator ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # fhir-generator ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # fhir-generator ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # fhir-generator ---
[INFO] Building jar: Z:\work\backend\fhir-generator\target\fhir-generator-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.921 s
[INFO] Finished at: 2019-07-30T11:21:25+02:00
[INFO] Final Memory: 12M/208M
[INFO] ------------------------------------------------------------------------
The problem is that no classes were generated in target/generated-sources folder. Any ideas about it? Tnx in advance
By default jsonschema2pojo plugin generates the files to target/java-gen/ folder, not the one you have specified.

gradle: Java API for JSON Processing (JSR 374)

How are the dependencies for JSON Processing, JSR 374, handled from gradle? Working examples would be greatly appreciated.
context: below is what I have with maven; looking to migrate this to gradle.
build is ok, even if there are duplicates:
thufir#dur:~/NetBeansProjects/HelloJsonMaven$
thufir#dur:~/NetBeansProjects/HelloJsonMaven$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloJsonMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # HelloJsonMaven ---
[INFO] Deleting /home/thufir/NetBeansProjects/HelloJsonMaven/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # HelloJsonMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # HelloJsonMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /home/thufir/NetBeansProjects/HelloJsonMaven/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # HelloJsonMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/thufir/NetBeansProjects/HelloJsonMaven/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # HelloJsonMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # HelloJsonMaven ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # HelloJsonMaven ---
[INFO] Building jar: /home/thufir/NetBeansProjects/HelloJsonMaven/target/HelloJsonMaven-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:3.1.0:shade (default) # HelloJsonMaven ---
[INFO] Including javax.json:javax.json-api:jar:1.1 in the shaded jar.
[INFO] Including org.glassfish:javax.json:jar:1.0.4 in the shaded jar.
[WARNING] Discovered module-info.class. Shading will break its strong encapsulation.
[WARNING] javax.json-1.0.4.jar, javax.json-api-1.1.jar define 25 overlapping classes:
[WARNING] - javax.json.stream.JsonParser
[WARNING] - javax.json.stream.JsonParserFactory
[WARNING] - javax.json.JsonString
[WARNING] - javax.json.JsonValue
[WARNING] - javax.json.stream.JsonLocation
[WARNING] - javax.json.Json
[WARNING] - javax.json.stream.JsonParsingException
[WARNING] - javax.json.stream.JsonParser$Event
[WARNING] - javax.json.JsonWriter
[WARNING] - javax.json.JsonValue$ValueType
[WARNING] - 15 more...
[WARNING] maven-shade-plugin has detected that some class files are
[WARNING] present in two or more JARs. When this happens, only one
[WARNING] single version of the class is copied to the uber jar.
[WARNING] Usually this is not harmful and you can skip these warnings,
[WARNING] otherwise try to manually exclude artifacts based on
[WARNING] mvn dependency:tree -Ddetail=true and the above output.
[WARNING] See http://maven.apache.org/plugins/maven-shade-plugin/
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /home/thufir/NetBeansProjects/HelloJsonMaven/target/HelloJsonMaven-1.0-SNAPSHOT.jar with /home/thufir/NetBeansProjects/HelloJsonMaven/target/HelloJsonMaven-1.0-SNAPSHOT-shaded.jar
[INFO] Dependency-reduced POM written at: /home/thufir/NetBeansProjects/HelloJsonMaven/dependency-reduced-pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.616 s
[INFO] Finished at: 2017-10-21T12:15:07-07:00
[INFO] Final Memory: 18M/61M
[INFO] ------------------------------------------------------------------------
thufir#dur:~/NetBeansProjects/HelloJsonMaven$
thufir#dur:~/NetBeansProjects/HelloJsonMaven$
and the JAR actually runs:
thufir#dur:~/NetBeansProjects/HelloJsonMaven$
thufir#dur:~/NetBeansProjects/HelloJsonMaven$ java -jar target/HelloJsonMaven-1.0-SNAPSHOT.jar
Oct 21, 2017 12:15:19 PM net.bounceme.dur.hello_json_maven.Main props
INFO: {foo=bar}
Oct 21, 2017 12:15:20 PM net.bounceme.dur.hello_json_maven.JsonOperations createJsonObject
INFO: creating..
Oct 21, 2017 12:15:20 PM net.bounceme.dur.hello_json_maven.Main json
INFO: {"name":"Falco","age":3,"biteable":false}
thufir#dur:~/NetBeansProjects/HelloJsonMaven$
sample code:
package net.bounceme.dur.hello_json_maven;
import java.math.BigDecimal;
import java.util.logging.Logger;
import javax.json.Json;
import javax.json.JsonObject;
public class JsonOperations {
private static final Logger log = Logger.getLogger(JsonOperations.class.getName());
public void loadJsonFromFile(String jsonFileName) {
log.info(jsonFileName);
}
public JsonObject createJsonObject() {
// Create Json and serialize
log.info("creating..");
JsonObject json = Json.createObjectBuilder()
.add("name", "Falco")
.add("age", BigDecimal.valueOf(3))
.add("biteable", Boolean.FALSE).build();
String result = json.toString();
log.fine(json.toString());
return json;
}
}
Having been down this road before, seems prudent to ask before going too far down any false paths.
pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>4.0.0</modelVersion>
<groupId>net.bounceme.dur</groupId>
<artifactId>HelloJsonMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>net.bounceme.dur.hello_json_maven.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.json/javax.json-api -->
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
</project>

Build is Success but No sources to compile

Maven test output in the Eclipse console:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for Mabi:Mabi:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.seleniumhq.selenium:selenium-java:jar -> duplicate declaration of version 2.45.0 # line 20, column 21
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-surefire-plugin # line 74, column 10
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Mabi 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Mabi ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\workspace\Mabi\src\com.TestCase
[INFO]
[INFO] --- maven-compiler-plugin:3.5:compile (default-compile) # Mabi ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 166 source files to E:\workspace\Mabi\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Mabi ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\workspace\Mabi\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5:testCompile (default-testCompile) # Mabi ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) # Mabi ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.287 s
[INFO] Finished at: 2016-03-23T11:32:40+05:30
[INFO] Final Memory: 21M/283M
[INFO] ------------------------------------------------------------------------
Above image shows the directory of my project but when I run the project via Maven it gives me the above result without running the test. Looking forward for some accurate solutions.
And this is what my POM.XML file looks like:
<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>4.0.0</modelVersion>
<groupId>Mabi</groupId>
<artifactId>Mabi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.40.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/com.TestCase</directory>
<includes>
<include>**/com.*TestCase.java</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source/>
<target/>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<inherited>true</inherited>
<configuration>
<suiteXmlFile>testng.xml</suiteXmlFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
Maven is all about "convention over configuration" idiom. In order that maven-surefire-plugin will run your testcases it expects to find it under src/test/java, hence, you should follow the maven's standard directory layout and put all your test cases under src/test/java.

Maven can't build a project with multiple source directories

I'm converting in maven an old project that originally rely on eclipse and ant to build.
Stated that I can't chancge the directory layout of that project, I would like to produce some artifact similar to ones build with that ant script. The original project, build all classes with from subprojects in one directory with eclipse, then package the resulting classes with ant in subpackages (different from subprojects).
To deal with this requirements I've done the following structure: (as now only one of the subpackage)
warp-parent
|
|- pom.xml
|- warp-client
| |
| | - pom.xml
the parent pom is the following:
<?xml version="1.0" encoding="UTF-8"?>
<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>4.0.0</modelVersion>
<groupId>it.sinesy.warp</groupId>
<artifactId>warp-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>warp-parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>../../src</source>
<source>../../srcj2ee</source>
<source>../../srcjsf</source>
<source>../../srcrest</source>
<source>../../srcswing</source>
<source>../../srctest</source>
<source>../../srcweb</source>
<source>../../srcws</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
<modules>
<module>warp-client</module>
</modules>
</project>
and the child one:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.sinesy.warp</groupId>
<artifactId>warp-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>it.sinesy.warp</groupId>
<artifactId>warp-client</artifactId>
<version>1.0-SNAPSHOT</version>
<name>warp-client</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<includes>
<include>**</include>
<!--
<include>**/it/tinet/warp/swing/**/java/*</include>
<include>**/it/tinet/warp/common/**/java/*</include>
<include>**/it/tinet/warp/swing/**/client/*</include> -->
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
When I try to compile to compile the parent pom I got the following output, with no source compiled:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] warp-parent
[INFO] warp-client
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building warp-parent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # warp-parent ---
[INFO] Source directory: /home/elettronik/test/warp/warp_src/src added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcj2ee added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcjsf added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcrest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcswing added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srctest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcweb added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcws added.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building warp-client 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # warp-client ---
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/src added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcj2ee added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcjsf added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcrest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcswing added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srctest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcweb added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcws added.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # warp-client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/elettronik/test/warp/warp_src/mvn/warp-parent/warp-client/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # warp-client ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] warp-parent ....................................... SUCCESS [0.762s]
[INFO] warp-client ....................................... SUCCESS [1.389s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.389s
[INFO] Finished at: Fri Aug 16 14:03:32 CEST 2013
[INFO] Final Memory: 6M/109M
[INFO] ------------------------------------------------------------------------
Could someone give some advice to make this work? thanks to all.
Your parent-pom shows <packaging>pom</packaging> so the sources you define in the parent pom will not be compiled.

Categories