Chinese output of Gradle Run is displayed as "????????", while Java Run output is fine.
Output of Gradle run
?????
\u5f9e\u51b7\u6c23\u8d77\u6548
?????
Output of Java run
從冷氣起效
\u5f9e\u51b7\u6c23\u8d77\u6548
從冷氣起效
The Gradle project with Eclipse. Chinese output of Java Run can be displayed after setting "Properties" > "Resource" > "Text file encoding" to UTF-8.
Here is the Java code.
package testgradle;
import org.apache.commons.text.StringEscapeUtils;
public class Test {
public static void main(String[] args) {
String origin = "從冷氣起效";
String input = "\\u5f9e\\u51b7\\u6c23\\u8d77\\u6548";
String result = StringEscapeUtils.unescapeJava("\\u5f9e\\u51b7\\u6c23\\u8d77\\u6548");
System.out.println(origin);
System.out.println(input);
System.out.println(result);
}
}
I have tried to modify build.gradle file, but still the output of Gradle run is not as expected.
build.gradle
plugins {
id 'java'
id 'application'
id 'java-library'
}
jar {
manifest {
attributes 'Main-Class': 'testgradle.Test'
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
application {
mainClassName = 'testgradle.Test'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Test) {
systemProperty "file.encoding", "UTF-8"
}
javadoc.options.encoding = 'UTF-8'
compileJava.options.encoding = 'UTF-8'
repositories {
jcenter()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:28.2-jre'
implementation 'org.apache.commons:commons-text:1.9'
testImplementation 'junit:junit:4.12'
}
Please provide solution to solve the problem. Thanks!
I am stumped by this one so I'm looking for some help here.
I am developing a jHipster app with multiple database connections, built with gradle. The app runs fine with "./gradlew bootRun" but when I try to package a stand-alone war with "./gradlew -Pprod bootRepackage" and run it, I get this exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/babycenter/belle/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Duplicate XML entry for com.babycenter.belle.readonly.domain.InvoiceLineItem
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at com.babycenter.belle.BelleApp.main(BelleApp.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: java.lang.IllegalStateException: Duplicate XML entry for com.babycenter.belle.readonly.domain.InvoiceLineItem
at org.hibernate.cfg.annotations.reflection.XMLContext.addClass(XMLContext.java:140)
at org.hibernate.cfg.annotations.reflection.XMLContext.addDocument(XMLContext.java:105)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.<init>(AnnotationMetadataSourceProcessorImpl.java:94)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.<init>(MetadataBuildingProcess.java:147)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:141)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 22 common frames omitted
I am puzzled because the file it says the error is in, DatabaseConfiguration.java, should only read entities from the package com.babycenter.belle.domain, which the class/XML it says is duplicated, InvoiceLineItem, is not in.
Here are files that may be involved. Tell me if you would like to see another.
DatabaseConfiguration.java
package com.babycenter.belle.config;
import io.github.jhipster.config.JHipsterConstants;
import io.github.jhipster.config.liquibase.AsyncSpringLiquibase;
import liquibase.integration.spring.SpringLiquibase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
#Configuration
#EnableJpaRepositories(basePackages = "com.babycenter.belle.repository")
#EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
#EnableTransactionManagement
public class DatabaseConfiguration {
private final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class);
private final Environment env;
public DatabaseConfiguration(Environment env) {
this.env = env;
}
#Bean
public SpringLiquibase liquibase(#Qualifier("taskExecutor") TaskExecutor taskExecutor, #Qualifier("dataSource") DataSource dataSource,
LiquibaseProperties liquibaseProperties) {
// Start Liquibase asynchronously
SpringLiquibase liquibase = new AsyncSpringLiquibase(taskExecutor, env);
// Start Liquibase synchronously
//SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:config/liquibase/master.xml");
liquibase.setContexts(liquibaseProperties.getContexts());
liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema());
liquibase.setDropFirst(liquibaseProperties.isDropFirst());
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_NO_LIQUIBASE)) {
liquibase.setShouldRun(false);
} else {
liquibase.setShouldRun(liquibaseProperties.isEnabled());
log.debug("Configuring Liquibase");
}
return liquibase;
}
#Primary
#Bean(name = "dataSource")
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Primary
#Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, #Qualifier("dataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("com.babycenter.belle.domain")
.persistenceUnit("readwrite")
.build();
}
#Primary
#Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(#Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
ReadOnlyDatabaseConfiguration.java
package com.babycenter.belle.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
#Configuration
#EnableJpaRepositories(
entityManagerFactoryRef = "roEntityManagerFactory",
transactionManagerRef = "roTransactionManager",
basePackages = "com.babycenter.belle.readonly.repository")
#EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
#EnableTransactionManagement
public class ReadOnlyDatabaseConfiguration {
private final Logger log = LoggerFactory.getLogger(ReadOnlyDatabaseConfiguration.class);
#Bean(name = "roDataSource")
#ConfigurationProperties(prefix = "spring.datasource-ro")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "roEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean roEntityManagerFactory(EntityManagerFactoryBuilder builder, #Qualifier("roDataSource") DataSource dataSource) {
return
builder
.dataSource(dataSource)
.packages("com.babycenter.belle.readonly.domain")
.persistenceUnit("readonly")
.build();
}
#Bean(name = "roTransactionManager")
public PlatformTransactionManager roTransactionManager(#Qualifier("roEntityManagerFactory") EntityManagerFactory roEntityManagerFactory) {
return new JpaTransactionManager(roEntityManagerFactory);
}
}
InvoiceLineItem.java
package com.babycenter.belle.readonly.domain;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
/**
* An object representation of a row from the opr_invoice_line_item table in Redshift
*/
#Entity
#Table(name = "opr_invoice_line_item", schema = "advertising")
#Cacheable
#Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class InvoiceLineItem implements Serializable {
#Id
#Column(name = "invoice_line_item_id", insertable = false, updatable = false)
private Long invoiceLineItemId;
#Column(name = "sales_order_line_item_id", insertable = false, updatable = false)
private Long salesOrderLineItemId;
#Column(name = "primary_performance", insertable = false, updatable = false)
private Long primaryPerformance;
#Column(name = "third_party_performance", insertable = false, updatable = false)
private Long thirdPartyPerformance;
#Column(name = "invoice_units", insertable = false, updatable = false)
private String invoiceUnits;
#Column(name = "invoice_amount", insertable = false, updatable = false)
private Float invoiceAmount;
/**
* Assigned when possible - not a column in opr_invoice_line_item table
*/
private String billingPeriodName;
public Long getInvoiceLineItemId() {
return invoiceLineItemId;
}
public void setInvoiceLineItemId(Long invoiceLineItemId) {
this.invoiceLineItemId = invoiceLineItemId;
}
public Long getSalesOrderLineItemId() {
return salesOrderLineItemId;
}
public void setSalesOrderLineItemId(Long salesOrderLineItemId) {
this.salesOrderLineItemId = salesOrderLineItemId;
}
public Long getPrimaryPerformance() {
return primaryPerformance;
}
public void setPrimaryPerformance(Long primaryPerformance) {
this.primaryPerformance = primaryPerformance;
}
public Long getThirdPartyPerformance() {
return thirdPartyPerformance;
}
public void setThirdPartyPerformance(Long thirdPartyPerformance) {
this.thirdPartyPerformance = thirdPartyPerformance;
}
public String getInvoiceUnits() {
return invoiceUnits;
}
public void setInvoiceUnits(String invoiceUnits) {
this.invoiceUnits = invoiceUnits;
}
public Float getInvoiceAmount() {
return invoiceAmount;
}
public void setInvoiceAmount(Float invoiceAmount) {
this.invoiceAmount = invoiceAmount;
}
public String getBillingPeriodName() {
return billingPeriodName;
}
public void setBillingPeriodName(String billingPeriodName) {
this.billingPeriodName = billingPeriodName;
}
}
build.gradle
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
jcenter()
maven { url "http://repo.spring.io/plugins-release" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
classpath "org.springframework.build.gradle:propdeps-plugin:0.0.7"
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "org.sonarqube" version "2.5"
id "net.ltgt.apt" version "0.11"
id "io.spring.dependency-management" version "1.0.3.RELEASE"
id "com.moowork.node" version "1.2.0"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
apply plugin: 'java'
sourceCompatibility=1.8
targetCompatibility=1.8
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'propdeps'
apply plugin: 'com.moowork.node'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
defaultTasks 'bootRun'
group = 'com.babycenter.belle'
version = '0.0.1-SNAPSHOT'
description = ''
bootRepackage {
mainClass = 'com.babycenter.belle.BelleApp'
}
war {
}
springBoot {
mainClass = 'com.babycenter.belle.BelleApp'
executable = true
buildInfo()
}
if (OperatingSystem.current().isWindows()) {
task pathingJar(type: Jar) {
dependsOn configurations.runtime
appendix = 'pathing'
doFirst {
manifest {
attributes 'Class-Path': configurations.runtime.files.collect {
it.toURL().toString().replaceFirst(/file:\/+/, '/').replaceAll(' ', '%20')
}.join(' ')
}
}
}
bootRun {
addResources = false
dependsOn pathingJar
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", pathingJar.archivePath)
}
}
} else {
bootRun {
addResources = false
systemProperties System.properties
}
}
//use jrebel to hot-deploy class changes during development
if (project.hasProperty('rebelAgent')) {
bootRun.jvmArgs += rebelAgent
}
test {
include '**/*UnitTest*'
include '**/*IntTest*'
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task cucumberTest(type: Test) {
include '**/CucumberTest*'
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
test.finalizedBy(cucumberTest)
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
reportOn cucumberTest
}
cucumberTest.finalizedBy(testReport)
apply from: 'gradle/docker.gradle'
apply from: 'gradle/sonar.gradle'
apply from: 'gradle/liquibase.gradle'
apply from: 'gradle/mapstruct.gradle'
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty('prod')) {
apply from: 'gradle/profile_prod.gradle'
} else if (project.hasProperty('stag')) {
apply from: 'gradle/profile_stag.gradle'
} else {
apply from: 'gradle/profile_dev.gradle'
}
if (project.hasProperty('graphite')) {
apply from: 'gradle/graphite.gradle'
}
if (project.hasProperty('prometheus')) {
apply from: 'gradle/prometheus.gradle'
}
configurations {
providedRuntime
compile.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
jcenter()
maven { url 'http://nexus.babycenter.com:8081/nexus/content/repositories/thirdparty/'}
}
dependencies {
compile "io.github.jhipster:jhipster:${jhipster_server_version}"
compile "io.dropwizard.metrics:metrics-core:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-jcache:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-jvm:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-servlet:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-json:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-servlets:${dropwizard_metrics_version}"
compile "net.logstash.logback:logstash-logback-encoder:${logstash_logback_encoder_version}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-csv:${jackson_dataformat_csv_version}"
compile "com.fasterxml.jackson.datatype:jackson-datatype-json-org"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
compile "com.fasterxml.jackson.core:jackson-annotations"
compile "com.fasterxml.jackson.core:jackson-databind"
compile "com.fasterxml.jackson.module:jackson-module-afterburner"
compile ("com.ryantenney.metrics:metrics-spring:${metrics_spring_version}")
compile "javax.cache:cache-api"
compile "org.hibernate:hibernate-core:${hibernate_version}"
compile ("com.zaxxer:HikariCP:${hikaricp_version}")
compile "org.apache.commons:commons-lang3:${commons_lang_version}"
compile "commons-io:commons-io:${commons_io_version}"
compile "javax.transaction:javax.transaction-api"
compile "org.ehcache:ehcache"
compile "org.hibernate:hibernate-jcache:${hibernate_version}"
compile "org.hibernate:hibernate-envers:${hibernate_version}"
compile "org.hibernate:hibernate-validator"
compile "org.hibernate:hibernate-entitymanager:${hibernate_version}"
compile ("org.liquibase:liquibase-core")
compile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"
compile "org.springframework.boot:spring-boot-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-loader-tools"
compile "org.springframework.boot:spring-boot-starter-mail"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-aop"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-security"
compile ("org.springframework.boot:spring-boot-starter-web") {
exclude module: 'spring-boot-starter-tomcat'
}
compile "org.springframework.boot:spring-boot-starter-undertow"
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
compile "org.zalando:problem-spring-web:${problem_spring_web_version}"
compile "org.springframework.boot:spring-boot-starter-cloud-connectors"
compile ("org.springframework:spring-context-support")
compile "org.springframework.security:spring-security-config"
compile "org.springframework.security:spring-security-data"
compile "org.springframework.security:spring-security-web"
compile ("io.springfox:springfox-swagger2:${springfox_version}") {
exclude module: 'mapstruct'
}
compile "io.springfox:springfox-bean-validators:${springfox_version}"
//The Data Warehouse (i.e. our read-only data source) is AWS Redshift
compile "com.amazon.redshift:RedShiftJDBC42:${redshift_jdbc_version}" //needs the RedShiftJDBC42 driver to work
compile "com.amazonaws:aws-java-sdk-redshift:${redshift_sdk_version}"
//our writable database is mysql
compile "mysql:mysql-connector-java"
compile "org.mapstruct:mapstruct-jdk8:${mapstruct_version}"
testCompile "org.awaitility:awaitility:${awaitility_version}"
testCompile "com.jayway.jsonpath:json-path"
testCompile "info.cukes:cucumber-junit:${cucumber_version}"
testCompile "info.cukes:cucumber-spring:${cucumber_version}"
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
testCompile "org.springframework.security:spring-security-test"
testCompile "org.springframework.boot:spring-boot-test"
testCompile "org.assertj:assertj-core:${assertj_version}"
testCompile "junit:junit"
testCompile "org.mockito:mockito-core"
testCompile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"
testCompile "org.hamcrest:hamcrest-library"
testCompile "com.h2database:h2"
optional ("org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}") {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
clean {
delete "target"
}
task cleanResources(type: Delete) {
delete 'build/resources'
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
task stage(dependsOn: 'bootRepackage') {
}
if (project.hasProperty('nodeInstall')) {
node {
version = "${node_version}"
npmVersion = "${npm_version}"
yarnVersion = "${yarn_version}"
download = true
}
}
compileJava.dependsOn processResources
processResources.dependsOn cleanResources,bootBuildInfo
bootBuildInfo.mustRunAfter cleanResources
Here are my versions of things:
jHipster 4.9.0
Spring Boot 1.5.8.RELEASE
Gradle 4.2
Groovy 2.4.11
I was eventually able to solve this myself.
I was using annotations in code to define my JPA entities PLUS an orm.xml file for named queries that had to have my result class entities defined. I had no persistence.xml file.
This ran fine with “./gradlew bootRun” but when I bundled a war it threw the exception listed above.
I learned when I package up a Spring Boot war with Hibernate JPA it will attempt to add annotated entities to orm.xml - and may even load orm.xml multiple times:
Duplicate XML entry | Hibernate orm.xml
Since I already had an entity definition there, it said there was a duplicate.
Basically I learned I can either use annotations in code, including named queries, OR define everything in orm.xml but I can’t mix the two.
A domain object is setup as the following:
#Data
#NoArgsConstructor
#Entity
public class Foo {
...
public Foo(...){
...
}
...
}
It is fine when I run a build with a set of tests. When I only run the test class, however, I get the following error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: No default constructor for entity: : com.abc.myapp.Foo; nested exception is org.hibernate.InstantiationException: No default constructor for entity: : com.abc.myapp.Foo
The project setup is with Spring Boot generated by the project generator on spring.io. And the following is the Gradle build file:
buildscript {
ext {
springBootVersion = '1.5.0.RC1'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'spring-data-samples'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}
And IDE is Intellij Idea.
What is missing?
I am using gradle application plugin to run my application. Below is my build.gradle:
group 'demo.jersey'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.5
mainClassName = "com.example.Main"
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.22.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
When I run gradle run, I can see my application is launched but it got shutdown immediately. Below is my Main class. Do you know how to block the application without shutting down?
package com.example;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import java.io.IOException;
import java.net.URI;
public class Main {
public static final String BASE_URI = "http://localhost:8080/myapp/";
public static HttpServer startServer() {
final ResourceConfig rc = new ResourceConfig().packages("com.example");
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.stop();
}
}
It stops because you invoke server.stop(); explicitly so the program finishes. Comment out this line and it will keep on running and listening for incoming requests.
I have a root project with three subprojects
root
|
|-subA
|-subB
|-subB
the build.gradle file in root has this content
allprojects {
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.zeromq:jeromq:0.3.+'
compile files('../lib/tibrvj.jar')
}
eclipse {
classpath {
downloadJavadoc=true
}
}
sourceSets {
main.java.srcDirs = ['src/main/java']
main.resources.srcDirs = ['src/main/resources']
test.java.srcDirs = ['src/test/java']
test.resources.srcDirs = ['src/test/resources']
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
task srcDirs << {
subprojects.sourceSets.main.java.srcDirs.each{f -> println(f)}
subprojects.sourceSets.main.resources.srcDirs.each{f -> println(f)}
subprojects.sourceSets.test.java.srcDirs.each{f -> println(f)}
subprojects.sourceSets.test.resources.srcDirs.each{f -> println(f)}
}
I do not know how I can create all the directories with this config. The other gradle.build files are empty at the moment
Unless you're trying to change from the defaults, you shouldn't need to set the sourceSets directories in the subprojects.
Have you tried something like:
subprojects {
task makeSrcDirs << {
sourceSets.main.java.srcDirs*.mkdirs()
sourceSets.main.resources.srcDirs*.mkdirs()
sourceSets.test.java.srcDirs*.mkdirs()
sourceSets.test.resources.srcDirs*.mkdirs()
}
}