Wildfly and Jackson #JsonIgnore annotation - java

I am fairly new to Wildfly and some parts of Java EE.
I have a rest service using RestEasy running on wildfly. My 'User' entity has an 'AccessToken' entity. Ideally, i'd like to be able to send the User entity as a JSON without it also sending the access token.
I did some research and found I should be able to use #JsonIgnore for exactly this. However, this annotation isn't available - probably a mistake in my POM.
If I understand correctly, Wildfly uses Jackson so the annotations should be 'provided'. I used a "bom" and what I thought was all of the provided parts, but I'm missing something?
Here is my pom.xml which originated from the quickstart through IntelliJ:
<?xml version="1.0" encoding="UTF-8"?>
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the #authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<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>com.example</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>WildFly Quickstarts: example</name>
<description>A starter Java EE 7 webapp project for use on JBoss WildFly / WildFly, generated from the jboss-javaee6-webapp archetype</description>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
<!-- Define the version of the JBoss BOMs we want to import to specify
tested stacks. -->
<version.jboss.bom>8.0.0.Final</version.jboss.bom>
<!-- other plugin versions -->
<version.compiler.plugin>3.1</version.compiler.plugin>
<version.surefire.plugin>2.16</version.surefire.plugin>
<version.war.plugin>2.5</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can
read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
from the Hibernate family of projects) -->
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- First declare the APIs we depend on and need for compilation. All
of them are provided by JBoss WildFly -->
<!-- Import the CDI API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss WildFly -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the EJB API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as #Email -->
<!-- Hibernate Validator is shipped in JBoss WildFly -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Now we declare any tools needed -->
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
typesafe criteria queries -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
<!-- Annotation processor that raising compilation errors whenever constraint
annotations are incorrectly used. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<scope>provided</scope>
</dependency>
<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Optional, but highly recommended -->
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
JPA from JUnit/TestNG -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<!-- Facebook library -->
<dependency>
<groupId>com.restfb</groupId>
<artifactId>restfb</artifactId>
<version>1.17.0</version>
</dependency>
</dependencies>
<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The WildFly plugin deploys your war to a local WildFly container -->
<!-- To use, run: mvn package wildfly:deploy -->
</plugins>
</build>
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including Arquillian
tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I did try adding:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.4</version>
</dependency>
This lets me use #JsonIgnore but then it still shows this field in the JSON returned to the client. I think perhaps my wildfly is using an older version of jackson (1.x) rather than 2? (This gives me that impression: JsonIgnoreProperties not working)

Annotation #JsonIgnore is a part of Jackson annotation jar.
To include it, use following dependency in your pom file.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.4</version>
</dependency>

Related

Why maven won't deploy my project and how can i fix this issue?

Am using JBOSS EAP-7.3.0
java 9
If we assume the "javax" dependency which is currently called "jakarta" is the one to be used it with it's latest version it didn't solve the problem. Feels like no matter what version of javax i add it won't work!!!
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the #authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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.example</groupId>
<artifactId>mssggg</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>WildFly Quickstarts: mssggg</name>
<description>A starter Java EE 7 webapp project for use on JBoss WildFly / WildFly, generated from the jboss-javaee6-webapp archetype</description>
<url>http://wildfly.org</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
<!-- Define the version of the JBoss BOMs we want to import to specify
tested stacks. -->
<version.jboss.bom>8.2.1.Final</version.jboss.bom>
<!-- other plugin versions -->
<version.compiler.plugin>3.1</version.compiler.plugin>
<version.surefire.plugin>2.16</version.surefire.plugin>
<version.war.plugin>3.3.2</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can
read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
from the Hibernate family of projects) -->
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- First declare the APIs we depend on and need for compilation. All
of them are provided by JBoss WildFly -->
<!-- Import the CDI API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss WildFly -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the EJB API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as #Email -->
<!-- Hibernate Validator is shipped in JBoss WildFly -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included in
JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Now we declare any tools needed -->
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
typesafe criteria queries -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
<!-- Annotation processor that raising compilation errors whenever constraint
annotations are incorrectly used. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<scope>provided</scope>
</dependency>
<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Optional, but highly recommended -->
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
JPA from JUnit/TestNG -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<!-- API, java.xml.bind module -->
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<!-- API, java.xml.bind module -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<!-- Runtime, com.sun.xml.bind module -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
</dependencies>
<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The WildFly plugin deploys your war to a local WildFly container -->
<!-- To use, run: mvn package wildfly:deploy -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<configuration>
<hostname>localhost</hostname>
<port>9990</port>
<username>admin</username>
<password>*******</password>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including Arquillian
tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests
in your WildFly instance -->
<!-- This profile will start a new WildFly instance, and execute the
test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
<id>arq-wildfly-managed</id>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests
in a remote WildFly instance -->
<!-- Run with: mvn clean test -Parq-wildfly-remote -->
<id>arq-wildfly-remote</id>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app
will need. -->
<!-- By default that is to put the resulting archive into the 'deployments'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
After using
mvn clean
no errors is showing
mvn install
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project mssggg: Fatal error compiling: java.lang.NoClassDefFoundError: ja
vax/xml/bind/JAXBException: javax.xml.bind.JAXBException -> [Help 1]
mvn wildfly:deploy
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project mssggg: Fatal error compiling: java.lang.NoClassDefFoundError: ja
vax/xml/bind/JAXBException: javax.xml.bind.JAXBException -> [Help 1]
Any idea thanks in advance!!!
You're using version 4.0.0 of JAXB, which is too new since in version 3.0 classes were moved from javax.xml.* to the new jakarta.xml.* packages.
Try version 2.3.0. You may also want to take a look at this comprehensive answer.

Unable to build "Bookshelf app for Java on App Engine standard environment" example from google, issue with pom.xml?

I am trying to get the bookshelf app for Java on APP engine
"https://cloud.google.com/java/getting-started-appengine-standard/tutorial-app"
I have performed all the steps like setting up billing for my project, enabling APIs and downloading the SDK.
I have cloned the repo i.e.
git clone https://github.com/GoogleCloudPlatform/getting-started-java.git
Then i proceed to run
mvn -Plocal clean appengine:devserver
from the directory
getting-started-java/bookshelf-standard/2-structured-data
This is where things get weird. In pom.xml when i set the appengine maven plugin and appengine-api-1.0-sdk version to 1.9.73 which is the latest version
I get the error
Error opening zip file or JAR manifest missing :
/home/anirudh/.m2/repository/com/google/appengine/appengine-java-sdk/1.9.73/appengine-java-sdk/appengine-java-sdk-1.9.73/lib/agent/appengine-agent.jar
Now i tried using an older version maven plugin and appengine-api-1.0-sdk namely
i get unable to create a DevAppserver
[INFO] java.lang.RuntimeException: Unable to create a DevAppServer
[INFO] at
com.google.appengine.tools.development.DevAppServerFactory.doCreateDevAppServer(DevAppServerFactory.java:401)
[INFO] at
com.google.appengine.tools.development.DevAppServerFactory.access$000(DevAppServerFactory.java:31)
[INFO] at
com.google.appengine.tools.development.DevAppServerFactory$1.run(DevAppServerFactory.java:318)
[INFO] at
com.google.appengine.tools.development.DevAppServerFactory$1.run(DevAppServerFactory.java:315)
[INFO] at
java.base/java.security.AccessController.doPrivileged(Native Method)
[INFO] at
com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:314)
[INFO] at
com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:384)
[INFO] at
com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:45)
[INFO] at
com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:257)
[INFO] at
com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:248)
[INFO] Caused by: java.lang.ClassCastException: ClassLoader is
jdk.internal.loader.ClassLoaders$AppClassLoader#4459eb14, not a
URLClassLoader. [INFO] at
com.google.apphosting.utils.security.SecurityManagerInstaller.generatePolicyFile(SecurityManagerInstaller.java:139)
[INFO] at
com.google.apphosting.utils.security.SecurityManagerInstaller.install(SecurityManagerInstaller.java:94)
[INFO] at
com.google.appengine.tools.development.DevAppServerFactory.doCreateDevAppServer(DevAppServerFactory.java:377)
Please find my pom file
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project> <!-- REQUIRED -->
<modelVersion>4.0.0</modelVersion> <!-- REQUIRED -->
<packaging>war</packaging> <!-- REQUIRED -->
<groupId>com.example.standard.gettingstarted</groupId>
<artifactId>bookshelf-standard-2</artifactId> <!-- Name of your project -->
<version>1.0-SNAPSHOT</version> <!-- xx.xx.xx -SNAPSHOT means development -->
<parent> <!-- Only used for testing - NOT REQUIRED -->
<groupId>com.example.standard.gettingstarted</groupId>
<artifactId>bookshelf-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<properties>
<!-- [START config] -->
<bookshelf.storageType>datastore</bookshelf.storageType> <!-- datastore or cloudsql -->
<sql.dbName>bookshelf</sql.dbName> <!-- A reasonable default -->
<!-- Instance Connection Name - project:region:dbName -->
<!-- -Dsql.instanceName=localhost to use a local MySQL server -->
<sql.instanceName>DATABASE-connectionName-HERE</sql.instanceName> <!-- See `gcloud sql instances describe [instanceName]` -->
<sql.userName>root</sql.userName> <!-- A reasonable default -->
<sql.password>MYSQL-ROOT-PASSWORD-HERE</sql.password> <!-- -Dsql.password=myRootPassword1234 -->
<!-- [END config] -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <!-- REQUIRED -->
<maven.compiler.target>1.8</maven.compiler.target> <!-- REQUIRED -->
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
<maven.compiler.failOnWarning>true</maven.compiler.failOnWarning>
<maven.war.filteringDeploymentDescriptors>true</maven.war.filteringDeploymentDescriptors>
<appengine-maven.version>1.9.10</appengine-maven.version>
</properties>
<!-- THINGS ONLY USED WHEN RUN LOCALLY -->
<profiles>
<profile>
<id>local</id>
<dependencies>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.2</version>
</dependency>
<dependency> <!-- http://dev.mysql.com/doc/connector-j/en/ -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version> <!-- v5.x.x is Java 7, v6.x.x is Java 8 -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-appengine</artifactId>
<version>1.21.0</version>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.71</version>
</dependency>
<dependency> <!-- REQUIRED -->
<groupId>javax.servlet</groupId> <!-- Java Servlet API -->
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope> <!-- Provided by the Jetty Servlet engine -->
</dependency>
<dependency> <!-- Java Server Pages -->
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
</dependency>
<dependency> <!-- JSP standard tag library -->
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency> <!-- Apache Taglibs -->
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency> <!-- Google Core Libraries for Java -->
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <!-- https://github.com/google/guava/wiki -->
<!-- Guava v21.0 doesn't support Java7 -->
<version>20.0</version>
<scope>compile</scope>
</dependency>
<dependency> <!-- http://www.joda.org/joda-time/ -->
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.1</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
</dependency>
<!-- Selenium chokes without this, for some reason. -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency> <!-- Google Cloud Client Library for Java -->
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud</artifactId>
<version>0.5.1</version>
</dependency>
</dependencies>
<build>
<!-- Optional - for hot reload of the web application when using an IDE Eclipse / IDEA -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.71</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration></plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
From the stack trace, it looks like you're trying to run with Java 9+. Try running with Java 8.

Spring Boot REST on Google App Engine throws 502

I have been struggling with this for about a week and nothing I have seen on SO has worked for me. I have a REST API built on Spring Boot that I am trying to deploy to the Google App Engine. Running locally is fine and when I run it on the GAE emulator it works fine as well; however, once I deploy using mvn appengine:deploy I get a successful build but when trying the endpoints I only get a 502. I'm not sure where the logs are so this is really kicking my butt.
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.admin</groupId>
<artifactId>admin-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- Exclude this for deployment only -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- other project dependencies -->
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
<!-- end other project specific dependencies -->
<!-- Dependencies provided during deployment -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- End dependencies for deployment -->
<!-- Dependencies for local -->
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-tomcat</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- End dependencies for local -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<project>project-id-from-GAE-here</project
</configuration>
</plugin>
</plugins>
</build>
</project>
My application class is a simple annotated #SpringBootApplication class. I have 2 controllers with annotation of #RestController and simple #RequestMapping methods. One of the REST controllers is for the /_ah/health endpoint that returns 200 since one post mentioned constant restarts being triggered by the lack of a healthcheck endpoint.
I have a simple application.yml for my value injections and created an app.yaml file placed in src/main/appengine
runtime: java
env: flexible
threadsafe: true
manual_scaling:
instances: 1
handlers:
- url: /.*
script: this field is required, but ignored
runtime_config:
jdk: openjdk8
I am at a complete loss on this. It is my first GAE deployment with hopefully more to go. (I also am not using Docker yet since I am on a Windows 10 machine that breaks when I load Docker on it.)
UPDATE
I did notice that I had forgotten to put my project id under the maven plugin. Once I did that I got errors about not finding the app.yaml. I realized that since I am using a flexible environment, I did not need the appengine-web.xml and I had my file misnamed as app.yml rather than app.yaml. I updated my question with this and I am still getting a 502 after a successful deployment.
I realized my trial period with GAE included tech support so I contacted them. The asked for my pom and app.yaml. Their response was to add the following to my app.yaml "Since Java is known for consuming high memory usage, there is an overhead process consumed more than the approximate 0.4GB value"
resources:
cpu: 2
memory_gb: 2.3
disk_size_gb: 10
volumes:
- name: ramdisk1
volume_type: tmpfs
size_gb: 0.5
They also provided this link for reference: https://cloud.google.com/appengine/docs/flexible/java/configuring-your-app-with-app-yaml#resource-settings
Once I did this, my application started working just fine.
EDIT
If you have a simple application, set cpu:1 since you get billed on CPU hours and your daily quota is 28 and with 2 CPUs you end up with 48 CPU hours. I burned through the free $300 credit in 1 month because their tutorials setup a RDB ($80) that doesn't get used and doesn't show to kill the project. Also make sure when deploying something new you delete the old versions or you will be charged for every version that is up.

Error when deploying project

I have a problem with deploying a project created with maven. I make a clean project i try to deploy it with "mvn clean package jboss-as:deploy" immediately but i get this error: "The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid version could be found". It felt strange to me, beacuse the project is "clean". So i found this: The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid version could be found but then just another error appeared instead of the older. I have jboss 7.1.1, and jdk 6 (for some reason I couldn't get newer version), ubuntu 10.04.4 LTS 64-bit.
I would appreciate some help
//Edit: 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.edu.agh.soa</groupId>
<artifactId>zad1h</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>zad1h application</name>
<modules>
<module>zad1h-ejb</module>
<module>zad1h-web</module>
<module>zad1h-ear</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Define the version of JBoss' Java EE 6 APIs we want to import.
Any dependencies from org.jboss.spec will have their version defined by this
BOM -->
<javaee6.web.spec.version>2.0.0.Final</javaee6.web.spec.version>
<!-- Alternatively, comment out the above line, and un-comment the line below to
use version 3.0.0.Beta1-redhat-1 which is a release certified
to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 maven repository. -->
<!--
<javaee6.web.spec.version>3.0.0.Beta1-redhat-1</javaee6.web.spec.version>
-->
</properties>
<dependencyManagement>
<dependencies>
<!-- Define the version of the EJB jar so that we don't need to
repeat ourselves in every module -->
<dependency>
<groupId>pl.edu.agh.soa</groupId>
<artifactId>zad1h-ejb</artifactId>
<version>1.0</version>
<type>ejb</type>
</dependency>
<!-- Define the version of the WAR so that we don't need to repeat
ourselves in every module -->
<dependency>
<groupId>pl.edu.agh.soa</groupId>
<artifactId>zad1h-web</artifactId>
<version>1.0</version>
<type>war</type>
<scope>compile</scope>
</dependency>
<!-- JBoss distributes a complete set of Java EE 6 APIs including
a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
a collection) of artifacts. We use this here so that we always get the correct
versions of artifacts. Here we use the jboss-javaee-web-6.0 stack (you can
read this as the JBoss stack of the Java EE Web Profile 6 APIs) -->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-web-6.0</artifactId>
<version>${javaee6.web.spec.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as #Email -->
<!-- Hibernate Validator is shipped in JBoss AS 7 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates
annotation processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- The JBoss AS plugin deploys your ear to a local JBoss AS
container -->
<!-- Due to Maven's lack of intelligence with EARs we need to
configure the jboss-as maven plugin to skip deployment for all modules. We
then enable it specifically in the ear module. -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.0.Beta1b</version>
<inherited>true</inherited>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Try this dependency, this one seems to be latest instead of maven-jboss-as-plugin
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.5.Final</version>
</plugin>
See
https://docs.jboss.org/jbossas/7/plugins/maven/latest/examples/deployment-example.html
Have you tried to delete the .m2 local repo?
It's a good work-around for problem like yours...

Java cannot find ResteasyClient despite everything accounted for in pom

In my prototype projects, I work on implementing very simple REST service - both server (backend) and client that in fact is server too (frontend). Backend server works fine, but with client I encountered very, very strange problem. In Eclipse I have project "frontend" that has this bean called FrontEndPageBean.java:
package org.mader.demo.frontend;
import javax.faces.bean.*;
import javax.ws.rs.core.*;
/** Bean to show off frontend handling of REST. */
#ManagedBean
public class FrontEndPageBean
{
/**
* Resolve data from backend through REST service.
* #return Data as text.
*/
public String getRestData()
{ // Retrieve RESTful service using client API from JAX-RS 2.0
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://127.0.0.1:8080/backend/rest/data/1");
Response response = target.request().get();
// Read output in string format
String value = response.readEntity(String.class);
System.out.println(value);
response.close();
return value;
}
}
It is called in home.xhtml like that:
Text resolved by REST from backend: #{frontEndPageBean.restData}
This is my 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>org.mader.demo</groupId>
<artifactId>frontend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Frontend App</name>
<description>Demonstration Frontend App.</description>
<properties>
<webapp.directory>src/main/webapp</webapp.directory>
<jboss.home>${env.JBOSS_HOME}</jboss.home>
<!-- plugin versions -->
<version.war.plugin>2.1.1</version.war.plugin>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<!-- other -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>JBOSS_NEXUS</id>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency> <!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill of Materials (BOM). -->
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Standard libraries. -->
<dependency> <!-- CDI API -->
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <!-- Common Annotations API (JSR-250) -->
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <!-- RESTeasy -->
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <!-- JSF -->
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin> <!-- To use, run: mvn package wildfly:deploy -->
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.0.Beta1</version>
</plugin>
</plugins>
</build>
</project>
Problem is that Eclipse does not recognize ResteasyClientBuilder, ResteasyClient nor ResteasyWebTarget. In tooltip it reads "ResteasyClient cannot be resolved to a type". No import options visible. It does not compile. It Just Does Not Work(TM).
According to various pages about consuming REST, ResteasyClient client = new ResteasyClientBuilder().build(); is kosher way. Only thing that I can think up is that there is something to add to POM, some missing dependency. Visit to https://mvnrepository.com/artifact/org.jboss.spec/jboss-javaee-all-7.0/1.0.0.Final does not help much, nor checking code of ResteasyClient - it looks like it should be already covered. Surely I missed something...
Environment: Java 1.7, Eclipse Kepler, Wildfly 8.0
Indeed, entries in POM were missing.
I needed to add other entries like that:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.6.Final</version>
<scope>provided</scope>
</dependency>
Note fully specified version and scope still being "provided".
I lost a lot of time chasing shadows. Lack of directly specified org.jboss.resteasy:resteasy-client etc in http://mvnrepository.com/artifact/org.jboss.spec/jboss-javaee-7.0/1.0.0.Final was surefire way to put me on wrong track.

Categories

Resources