schema-codegen failed: A required class was missing while executing - jibx

I am getting the below error while trying to build an application. This is failing while running tests otherwise it is fine :
WARNING: Error injecting: org.jibx.maven.SchemaCodeGenMojo
java.lang.NoClassDefFoundError: org/jibx/runtime/JiBXException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483)
at java.lang.Class.getDeclaredConstructors(Class.java:1891)
[ERROR] Failed to execute goal org.jibx:maven-jibx-plugin:1.2.2:schema-codegen (generate-java-code-from-xml-schema) on project b2bservices-xml-api:
Execution generate-java-code-from-xml-schema of goal org.jibx:maven-jibx-plugin:1.2.2:schema-codegen failed: A required class was missing while executing org.jibx:maven-jibx-plugin:1.2.2:schema-codegen: org/jibx/runtime/JiBXException
My pom looks like :
<dependencies>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-bind</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-run</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<id>generate-java-code-from-xml-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<targetDirectory>${basedir}/src/main/java</targetDirectory>
<directory>${basedir}/src/main/resources/schemas</directory>
<includes>
<includes>xml_services.xsd</includes>
</includes>
<options>
<package>com.company.b2c.product.xml</package>
<prefer-inline>true</prefer-inline>
<show-schema>true</show-schema>
<binding-file-name>binding.xml</binding-file-name>
</options>
<verbose>true</verbose>
</configuration>
</execution>
</plugin>
</plugins>
</build>
Now this is getting failed during build process. Any assistance will be greatly appreciated.

You need to include the JiBX dependencies in your pom file:
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-run</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-extras</artifactId>
<version>1.2.5</version>
</dependency>
I would also recommend using a newer version of JiBX like 1.2.5.
Don Corley
JiBX contributor.

Related

Spring apllication run failed

Hey I'm getting this error and i cant solve it, thank you for your help
ERROR 7924 --- [ main] o.s.boot.SpringApplication : Application run failed
Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource
here is my pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>employeemanager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>employeemanager</name>
<description>Employee Manager App </description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
and my application.properties:
# mySQL configuration
spring.datasource.url=jbdc:mysql://localhost:3306/employeemanager
spring.datasource.username=root
spring.datasource.password=letmein
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
On Spring Boot 2.5.X data.sql scripts are now run before Hibernate is initialized. If you want to use data.sql to populate a schema created by Hibernate try adding the following to your application.properties spring.jpa.defer-datasource-initialization=true.
# mySQL configuration
spring.datasource.url=jbdc:mysql://localhost:3306/employeemanager
there's a typo, its supposed to be jdbc not jbdc
As I do remember, I was facing similar issue during integration.
Could you please validate your pom.xml and application.properties/application.yaml configurations as below.
Sample - Maven Pom.xml
4.0.0
<groupId>com.example</groupId>
<artifactId>spring-boot-security-oauth2</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Application Properties - application.yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/bootdb
username: root
password: admin
jpa:
hibernate.ddl-auto: update
show-sql: true
user.datasource.driver-class-name: com.mysql.jdbc.Driver
For more detail you may go through following working examples:
https://thebasictechinfo.com/interview-preparation/spring-boot-oauth2-securing-rest-api/
https://thebasictechinfo.com/java-8/spring-boot-spring-security-with-database-authentication-mysql-rest-api-example/
Also, could you try with following properties.
spring.datasource.jdbcUrl=jdbc:mysql://localhost/bootdb?useSSL=false
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Enjoy :)

jparepository cannot be resolved to a type

I am trying to use JpaRepository but I am getting this error "jparepository cannot be resolved to a type."
My maven dependency is
`
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.3.2.RELEASE
com.example
accessing-data-jpa
0.0.1-SNAPSHOT
accessing-data-jpa
Demo project for Spring Boot
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
`
My student class is
package Repositry;
public interface Student_Repo extends JpaRepositry {
}
Please let me know what I have done wrong
Typo here.
It is JpaRepository not JpaRepositry
Also it expects 2 parameters.
Entity class
Type of primary key field (Integer/Long)
Like below.
Student_Repo extends JpaRepository<Student,Long>
This error might occur
As spelling error
If you commented out the Jpa dependency in pom.xml or didn't add it in the first place.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
HTH

Jersey - Maven - MessageBodyWriter not found for media type=application/json

Currently i have the problem that everything in Netbeans my webservice works but if i start the jar file with the command "java -jar FILENAME PARAMETERS there is the following error.
MessageBodyWriter not found for media type=application/json, type
=class java.util.ArrayList, genericType=java.util.List
I need an expert do solve this problem :/. It is very strange because when i execute the jar in Netbeans it works.
pom.xml
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>at.schneider.development</groupId>
<artifactId>PhotoBoothImageService</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>PhotoBoothImageService</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>[0.4, 0.5)</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>at.schneider.development.photoboothimageservice.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.26-b02</jersey.version>
<jdk.version>1.8</jdk.version>
</properties>
Function:
#GET
#Path("/getimages")
#Produces(MediaType.APPLICATION_JSON)
public List<Image> getImages() {
availableImages = getImageListFromDirectory(Paths.get(configuration.getProperties().get(BASE_DIR).toString()));
return availableImages;
}
Thanks in advice!
Best Regards
I found the answer in comment by Supercop89:
jersey-media-json-jackson has to be the first dependency.
Because maven-assembly-plugin squashes META-INF/services files, it seems the JacksonAutoDiscoverable SPI is gone.
By putting the dependency jersey-media-json-jackson at the top, it ends-up in a better state.
Here is a diff:
JSON FEATURES NOT WORKING
META-INF/services/org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
JSON FEATURES WORKING
META-INF/services/org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable:
org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable
So, putting the dependency at the top will make Json features work, at the expense of some other stuff that you (maybe) don't need.
There are some ways to merge the services in maven-assembly-plugin: Merging META-INF/services files with Maven Assembly plugin
See also: https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/using-container-descriptor-handlers.html
EDIT: I played a lot with maven-assembly-plugin as described in the links, but wasn't able to make that work. Eventually, I switched to maven-shade-plugin and it worked on my first try. It also displays information on what it does:
[INFO] Including org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.28 in the shaded jar.
If maven-assembly-plugin had done so, I wouldn't have to search for the problem for 1 hour. Also, it didn't need a bunch of xml. Personal conclusion: much easier with the latter.

JSON Dependency not working in Maven pom.xml

i am working on JAX-RS with Jersey, i have a resource class that return data to the client, i am able to return xml data as responce, but it's not working when i am trying to return JSON, i got the below ERROR
something wrong with my POM.xml?
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.amdocs.login.login</groupId>
<artifactId>login</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>login</name>
<build>
<finalName>login</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
</dependencies>
<properties>
<jersey.version>2.16</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.22</version>
</dependency>
thank you guys, i found the problem, this issue happened cause i worked with old jersey version, i just changed the version value from 2.16 to 2.22, and run Maven>update project, now it's working fine.

Error with Maven GAE Plugin + Google Cloud SQL

Here's my plugin configuration:
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<version>0.7.3</version>
<dependencies>
<dependency>
<groupId>net.kindleit</groupId>
<artifactId>gae-runtime</artifactId>
<version>${gae.version}</version>
<type>pom</type>
</dependency>
</dependencies>
<configuration>
<jvmFlags>
<jvmFlag>-Drdbms.server=local</jvmFlag>
<jvmFlag>-Drdbms.driver=com.mysql.jdbc.Driver</jvmFlag>
<jvmFlag>-Drdbms.url=jdbc:mysql://localhost:3306/prova?user=root&password=pass</jvmFlag>
</jvmFlags>
<serverId>appengine.google.com</serverId>
</configuration>
</plugin>
You can read more here: https://developers.google.com/cloud-sql/docs/developers_guide_java
First I had this trivial error, doing mvn gae:run
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
So I added the "real" driver to my pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
with no results. The error remains the same.
Part of the stacktrace:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at com.google.appengine.tools.development.DevAppServerClassLoader.loadClass(DevAppServerClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.google.appengine.api.rdbms.dev.LocalRdbmsServiceLocalDriver.registerDriver(LocalRdbmsServiceLocalDriver.java:84)
at com.google.appengine.api.rdbms.dev.LocalRdbmsServiceLocalDriver.init(LocalRdbmsServiceLocalDriver.java:73)
at com.google.appengine.api.rdbms.dev.LocalRdbmsService.init(LocalRdbmsService.java:85)
edit:
My new plugin conf:
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<version>0.9.2</version>
<dependencies>
<dependency>
<groupId>net.kindleit</groupId>
<artifactId>gae-runtime</artifactId>
<version>${gae.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
</dependencies>
<configuration>
<jvmFlags>
<jvmFlag>-Drdbms.server=local</jvmFlag>
<jvmFlag>-Drdbms.driver=com.mysql.jdbc.Driver</jvmFlag>
<jvmFlag>-Drdbms.url=jdbc:mysql://localhost:3306/prova?user=root&password=pass</jvmFlag>
</jvmFlags>
<serverId>appengine.google.com</serverId>
<!-- <sdkDir>${appengine.sdk.root}</sdkDir> -->
<!-- <appDir>${basedir}/war</appDir> -->
</configuration>
</plugin>
Ok I solved. I manually put mysql-connector-java-5.1.18-bin.jar in my sdk folder:
file:///opt/appengine-java-sdk-1.6.0/lib/impl/
Error changes in a more comfortable:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
Thank you for suggestions however
Or you can use maven-antrun-plugin do it for you at build time. No more manual intervention for your project team (I use this with the offical appengine-maven-plugin, you need to adapt the path for use with maven-gae-plugin) :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<!-- Use 'package' instead of 'install' if you want the Driver to be available for 'integration-test' -->
<phase>package</phase>
<configuration>
<target>
<!-- delete existing mysql jar from appengine sdk lib/impl -->
<delete>
<fileset
dir="${settings.localRepository}/com/google/appengine/appengine-java-sdk/${appengine.target.version}/appengine-java-sdk/appengine-java-sdk-${appengine.target.version}/lib/impl"
includes="**/mysql-connector-java*" />
</delete>
<!-- copy mysql jar into appengine sdk lib/impl -->
<copy
file="${settings.localRepository}/mysql/mysql-connector-java/${mysql.version}/mysql-connector-java-${mysql.version}.jar"
todir="${settings.localRepository}/com/google/appengine/appengine-java-sdk/${appengine.target.version}/appengine-java-sdk/appengine-java-sdk-${appengine.target.version}/lib/impl"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Did you add this to the plugins' dependencies as well ?
If it is the plugin's classpath it should be picked up by GAE.