martes, 24 de agosto de 2021

47. Tomcat stackoverflow in org.bouncycastle.en1 ..

 In this error, that basically says:

Unable to complete the scan for annotations for web application [/WEBPROP] 
due to a StackOverflowError. 
Possible root causes include a too low setting for -Xss and illegal cyclic 
inheritance dependencies. 
The class hierarchy being processed was 
  [org.bouncycastle.asn1.ASN1OutputStream->
   org.bouncycastle.asn1.DEROutputStream->
   org.bouncycastle.asn1.ASN1OutputStream
  ]

I have created a file setenv.sh in the bin folder of tomcat with this content 

export JAVA_HOME=/home/ximo/MyPrograms/jdk-15.0.2+7.OpenJ7

export CATALINA_OPTS="$CATALINA_OPTS -Xms1G -Xmx7G -Xss256M"  //DON'T WORK!!

If you don't have a StackOverflow error when increasing the Xss size you may get an OutOfMemory error, or even Tomcat cannot startup!!!

So you must try the Xss parameter ???

The question is solved in StackOverflow and there are 2 versions of the bcpprov-jdkXXXX.war in the dependencies.

In my case, this fact was due to the use of IText in its last version and JasperReports that uses internally IText v.2 





java.lang.IllegalStateException: Error starting child

        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)

        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)

        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1024)

        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1911)

        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)

        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)

        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)

        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)

        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:825)

        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:475)

        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1618)

        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)

        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)

        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)

        at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)

        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:946)

        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)

        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)

        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)

        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)

        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)

        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)

        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.startup.Catalina.start(Catalina.java:772)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)

        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.base/java.lang.reflect.Method.invoke(Method.java:564)

        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)

        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)

Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/WEBPROP]]

        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)

        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)

        ... 37 more

java.lang.IllegalStateException: Error starting child

        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)

        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)

        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1024)

        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1911)

        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)

        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)

        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)

        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)

        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:825)

        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:475)

        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1618)

        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)

        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)

        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)

        at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)

        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:946)

        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)

        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)

        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)

        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)

        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)

        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)

        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        at org.apache.catalina.startup.Catalina.start(Catalina.java:772)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)

        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.base/java.lang.reflect.Method.invoke(Method.java:564)

        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)

        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)

Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/WEBPROP]]

        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)

        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)

        ... 37 more

Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/WEBPROP] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.bouncycastle.asn1.ASN1OutputStream->org.bouncycastle.asn1.DEROutputStream->org.bouncycastle.asn1.ASN1OutputStream]

        at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2404)

        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2342)

        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:2294)

        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:2264)

        at org.apache.catalina.startup.ContextConfig.scanWebXmlFragment(ContextConfig.java:2172)

        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:2152)

        at org.apache.catalina.startup.ContextConfig.processClasses(ContextConfig.java:1408)

        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1303)

        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:986)

        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)

        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)

        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        ... 38 more

Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/WEBPROP] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.bouncycastle.asn1.ASN1OutputStream->org.bouncycastle.asn1.DEROutputStream->org.bouncycastle.asn1.ASN1OutputStream]

        at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2404)

        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2342)

        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:2294)

        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:2264)

        at org.apache.catalina.startup.ContextConfig.scanWebXmlFragment(ContextConfig.java:2172)

        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:2152)

        at org.apache.catalina.startup.ContextConfig.processClasses(ContextConfig.java:1408)

        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1303)

        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:986)

        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)

        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)

        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135)

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

        ... 38 more

domingo, 15 de agosto de 2021

46. Problems: Eclipse cannot run on server the gradle project


Error: Caused by: java.lang.IllegalStateException: Failed to determine project directory for dev mode. Directory '/home/eduard/Escriptori' does not look like a Maven or Gradle project. Ensure that you have run the prepare-frontend Maven goal, which generates 'flow-build-info.json', prior to deploying your application

Solution 1:

1. The target folder (delete and create again the target folder directly in the project folder)
2. Restart your computer (maybe an installed update was made recently and the computer needs to be restarted !!!!!)

Solution 2:

1. Delete the web.xml file in the src/main/webapp/WEB-INF folder. Eclipse tries to create it many times. Creating the empty file

beans.xml
in this folder may prevent Eclipse from creating if



FROM HERE, it is OUTDATED


1. To run in debug mode (NOT in production) 

Method 1: Deleting the generated files and regenerate them

 1. Delete these files and folders from the project ( the ones with orange backgroud)


2. Refresh the project (Click on the project and press F5)

3. Edit the file gradle.properties and set in the file

vaadinVersion=20.0.6

4. Verify you are using gradle 6.6 7.1.1 -> Note that the projects that are not Vaadin use gtradle 6.6

5. Edit the file build.gradle


// New in the Vaadin starting project version 19+
buildscript {
    repositories {
        maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
    }
}

plugins {
    id 'war'                                 //Generate a ".war" file
    id 'org.gretty' version '3.0.4'
    //id 'com.vaadin' version '20.0.0.alpha6'
    id 'com.vaadin' version '20.0.6'
    id 'java-library'  // only to admit "api" instead of "0.
    //id 'java-platform' //DON'T USE !!!! 
}

defaultTasks("clean", "build")

repositories {
    mavenCentral()
    //maven { url = "https://maven.vaadin.com/vaadin-addons" } //DON'T USE !!!

    jcenter() // jcenter is deprecated, however the Gretty plugin still uses stuff from jcenter: https://github.com/gretty-gradle-plugin/gretty/issues/192
}



project.war.destinationDirectory = file("$rootDir/../mytargets")  
project.archivesBaseName = 'p-aevaadin' 
project.version = '2.0'

gretty {
    contextPath = "/"  // it points to https://localhost:8080/
    servletContainer = "jetty9.4"
}


// The following pnpmEnable = true is not needed as pnpm is used by default,
// this is just an example of how to configure the Gradle Vaadin Plugin:
// for more configuraion options please see: https://vaadin.com/docs/latest/guide/start/gradle/#all-options
vaadin {
    pnpmEnable = true
    productionMode = false  //Not included in the starting-project generation 
    optimizeBundle = true
}

dependencies {
    // $vaadinVersion" is defined in gradle.properties
    //enforcedPlatform theoretically requires id java-platform
    //  but if you add it the FAILS!!! So don't put id 'java-platform' !!!
    implementation enforcedPlatform("com.vaadin:vaadin-bom:$vaadinVersion")

    // Vaadin
    //implementation("com.vaadin:vaadin-core")
    implementation("com.vaadin:vaadin")
    implementation("com.vaadin:vaadin-cdi")
    
    
    
    //providedCompile "javax.servlet:javax.servlet-api:3.1.0"   //generated by starting-project
    
    //Use only or jakarta.servet or jakarta.platform but not both at the same time --> genarate errors : The package jakarta.mail is accessible from more than one module: <unnamed>, jakarta.mail
    providedCompile "jakarta.servlet:jakarta.servlet-api:5.0.0" //replace javax by jakarta !!!!! 
    //providedCompile "jakarta.platform:jakarta.jakartaee-api:9.0.0" //replace javax by jakarta !!!!! 

    providedCompile "jakarta.annotation:jakarta.annotation-api:2.0.0"

    // logging
    // currently we are logging through the SLF4J API to SLF4J-Simple. See src/main/resources/simplelogger.properties file for the logger configuration
    implementation "org.slf4j:slf4j-simple:1.7.30"
    
    //=============LOMBOK BEGIN ============================
    // Not generated by the Vaadin starting-project
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
	
    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
    //=============LOMBOK END ==============================
    
	// This dependency is for local jars in the folder mylibs
    //implementation files(
    api files(
    	'../mytargets/a-annotations-1.0.jar', 
    	'../mytargets/a-basic-utils-1.0.jar', 
    	'../mytargets/a-report-utils-1.0.jar',
    	'../mytargets/b-base-control-model-1.0.jar', 
    	'../mytargets/b-other-utils-1.0.jar',
    	'../mytargets/c-dao-1.0.jar',
    	'../mytargets/c-model-aytos-1.0.jar',
    	//'../mytargets/c-model-castilla-1.0.jar',
    	//'../mytargets/c-model-eni-1.0.jar',
    	'../mytargets/c-model-gexflow-1.0.jar',
    	//'../mytargets/c-model-orve-1.0.jar',
    	'../mytargets/c-vaadin-basic-1.0.jar' )      
    
    implementation "org.jboss.weld.servlet:weld-servlet-shaded:3.1.7.Final"
    implementation "org.javassist:javassist:3.27.0-GA"
    providedCompile "jakarta.activation:jakarta.activation-api:2.0.1"
    implementation "com.sun.activation:jakarta.activation:2.0.1"
    
    /* HIbernate */
    implementation "org.hibernate:hibernate-core:5.4.31.Final"
    implementation "org.hibernate:hibernate-envers:5.4.31.Final"
    implementation "org.hibernate:hibernate-validator:7.0.1.Final" 
    
    /*DB Drivers */
    runtimeOnly "com.h2database:h2:1.4.200"
    implementation "org.postgresql:postgresql:42.2.20"
    implementation "net.sourceforge.jtds:jtds:1.3.1"
    
    /* Apache CMIS */
    implementation "org.apache.chemistry.opencmis:chemistry-opencmis-client-impl:1.1.0"
    
    /* JASPER REPORTS */
    implementation "net.sf.jasperreports:jasperreports:6.16.0"
    /* IText VELL pero el vol jasper reports*/
    implementation "com.lowagie:itext:2.1.7"
    implementation "com.itextpdf:itext7-core:7.1.15"  //Falta "type pom" ?????
   
    
}

6. Refresh Gradle (Right-click on the project -> Gradle -> Refresh Gradle project)

7. Clean the servers 

Right click on the first line (Tomcat) and click on these 2 actions

Now right click on the second line and select this action

8. Optionally run the Gradle task vaadinPrepareFrontEnd and vaasdinBuildFrontEnd


Verify that these files are created




if any of these files are missing, it is due to that the vaasdinBuildFrontEnd has not ended well maybe fail in the internet connection. NOTE that the target directory is missing! So the application maybe will not run!

Verify to Right-click on the project BuildPath ->Configure Build path ->Open the folder "project and External dependencies " and the folder "Web App Libraries" and click "Apply and Close" button





9. Right-click on the project and Run As -> Run on Server

2. To run in Production mode (NOT in debug) 

1. Change the variable productionMode to true in the file build.gradle 

2. Verify you are using gradle 6.6 7.1.1 -> Note that the projects that are not Vaadin use gtradle 6.6

3. Refresh Gradle (Right-click on the project -> Gradle -> Refresh Gradle project)

4. Execute the gradle task build


5. the war file should be generated


miércoles, 12 de mayo de 2021

45. Converting the project to Gradle

1. The process

 1. Create a new folder in the WorkSpace (MyWorkspace) for instance AEVaadin-20-01

2. Copy these files and folders from the last post project VaadinGradle02

  Files: build.gradle, gradle.properties, LICENSE (optional), README.md

  Folders: frontend, src.



3. Now import an existing gradle project , and select the folder (for instance in this example P0-AEVaadin-19-04). Select gradle version 6.6 7.1.1and the Java home












Perhaps there can be error. So review the Java Build Path in properties, and select the correct JDK 



Verify that the gradle.properties has this content:

#vaadinVersion=19.0.4  //Not used

vaadinVersion=20.0.6

Refresh project F5 

Gradle-> Regresh gradle poject


A. Now to see if it works change int the file build.gradle the variable productionMode to false and:

1. From Gradle Tasks tab -> "Your Project Name" -> build -> (clean and then build) and verify that the war was generated

2. Run as Run on Server and verify it runs


B. Now repeat the proces to see if it can generate the war file for production. Change in the build.gradle file the  variable  productionMode to false and:

1. From Gradle Tasks tab -> "Your Project Name" -> build -> (clean and then build) and verify that the war was generated

2. Copy the war to aTomvat webapp folder and try to deploy it

Here is an example of working build.gradle


// New in the Vaadin starting project version 19+
buildscript {
    repositories {
        maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
    }
}

plugins {
    id 'war'                                 //Generate a ".war" file
    id 'org.gretty' version '3.0.4'
    //id 'com.vaadin' version '20.0.0.alpha6'
    id 'com.vaadin' version '20.0.6'
    id 'java-library'  // only to admit "api" instead of "0.
}

defaultTasks("clean", "build")

repositories {
    mavenCentral()
    maven { url = "https://maven.vaadin.com/vaadin-addons" }

    jcenter() // jcenter is deprecated, however the Gretty plugin still uses stuff from jcenter: https://github.com/gretty-gradle-plugin/gretty/issues/192
}



project.war.destinationDirectory = file("$rootDir/../mytargets")  
project.archivesBaseName = 'p-aevaadin' 
project.version = '2.0'

gretty {
    contextPath = "/"  // it points to https://localhost:8080/
    servletContainer = "jetty9.4"
}


// The following pnpmEnable = true is not needed as pnpm is used by default,
// this is just an example of how to configure the Gradle Vaadin Plugin:
// for more configuraion options please see: https://vaadin.com/docs/latest/guide/start/gradle/#all-options
vaadin {
    pnpmEnable = true
    productionMode = false  //Not included in the starting-project generation 
    optimizeBundle = true
}

dependencies {
    // $vaadinVersion" is defined in gradle.properties
    implementation enforcedPlatform("com.vaadin:vaadin-bom:$vaadinVersion")

    // Vaadin
    //implementation("com.vaadin:vaadin-core")
    implementation("com.vaadin:vaadin")
    implementation("com.vaadin:vaadin-cdi")
    
    
    
    //providedCompile "javax.servlet:javax.servlet-api:3.1.0"   //generated by starting-project
    
    //Use only or jakarta.servet or jakarta.platform but not both at the same time --> genarate errors : The package jakarta.mail is accessible from more than one module: <unnamed>, jakarta.mail
    providedCompile "jakarta.servlet:jakarta.servlet-api:5.0.0" //replace javax by jakarta !!!!! 
    //providedCompile "jakarta.platform:jakarta.jakartaee-api:9.0.0" //replace javax by jakarta !!!!! 

    providedCompile "jakarta.annotation:jakarta.annotation-api:2.0.0"
    providedCompile "jakarta.activation:jakarta.activation-api:2.0.1"
    
    implementation "com.sun.activation:jakarta.activation:2.0.1"
    

    // logging
    // currently we are logging through the SLF4J API to SLF4J-Simple. See src/main/resources/simplelogger.properties file for the logger configuration
    implementation "org.slf4j:slf4j-simple:1.7.30"
    
    //=============LOMBOK BEGIN ============================
    // Not generated by the Vaadin starting-project
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
	
    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
    //=============LOMBOK END ==============================
    
	// This dependency is for local jars in the folder mylibs
    //implementation files(
    api files(
    	'../mytargets/a-annotations-1.0.jar', 
    	'../mytargets/a-basic-utils-1.0.jar', 
    	'../mytargets/a-report-utils-1.0.jar',
    	'../mytargets/b-base-control-model-1.0.jar', 
    	'../mytargets/b-other-utils-1.0.jar',
    	'../mytargets/c-dao-1.0.jar',
    	'../mytargets/c-model-aytos-1.0.jar',
    	//'../mytargets/c-model-castilla-1.0.jar',
    	//'../mytargets/c-model-eni-1.0.jar',
    	'../mytargets/c-model-gexflow-1.0.jar',
    	//'../mytargets/c-model-orve-1.0.jar',
    	'../mytargets/c-vaadin-basic-1.0.jar' )      
    
    implementation "org.jboss.weld.servlet:weld-servlet-shaded:3.1.7.Final"
    
    implementation "org.javassist:javassist:3.27.0-GA"
    
    /* HIbernate */
    implementation "org.hibernate:hibernate-core:5.4.31.Final"
    implementation "org.hibernate:hibernate-envers:5.4.31.Final"
    //implementation "org.hibernate:hibernate-testing:5.4.31.Final"
    implementation "org.hibernate:hibernate-validator:7.0.1.Final" 
    
    /*DB Drivers */
    runtimeOnly "com.h2database:h2:1.4.200"
    implementation "org.postgresql:postgresql:42.2.20"
    implementation "net.sourceforge.jtds:jtds:1.3.1"
    
    /* Apache CMIS */
    implementation "org.apache.chemistry.opencmis:chemistry-opencmis-client-impl:1.1.0"
    
    /* JASPER REPORTS */
    implementation "net.sf.jasperreports:jasperreports:6.16.0"
    /* IText VELL pero el vol jasper reports*/
    implementation "com.lowagie:itext:2.1.7"
    implementation "com.itextpdf:itext7-core:7.1.15"  //Falta "type pom" ?????
    
}


2. File structure

Important locations:

src/main/webapp/META-INF/context.xml (For JNDI pool of connections)

src/main/resources/META-INF/presistence.xml 

src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener

frontend/styles

frontend/font-awesome

gradle.build

gradle.properties


src
   |->main
   |   |->webapp
   |   |   |->WEB-INF       Not used (can be deleted)
   |   |   |   |->beans.xml Not used 
   |   |   |->skins
   |   |   |   |->ui
   |   |   |   |->content
   |   |   |->META-INF
   |   |   |   |>context.xml (JNDI pool of connections)
   |   |   |->imgs
   |   |   |   |->enterprise (or any particular folder with images)
   |   |   |->icons
   |   |   |   |->flags (or any particular folder with icons)
   |   |->resources
   |   |   |->view (in yaml or any partiular folder with some info)
   |   |   |->reports (or any partiular folder with jasper reports)
   |   |   |->readme (or any partiular folder with some info)
   |   |   |->properties (property files)
   |   |   |->META-INF
   |   |   |   |->services
   |   |   |      |->com.vaadin.flow.server.VaadinServiceInitListener
   |   |   |   |->persistence.xml
   |   |   |->i18n (all teh internationalization resources)
   |   |   |   |->file_en.properties ; file_es.properties
   |   |   |->docs (any doc )
   |   |   |->simplelogger.properties
   |   |->java 
   |   |   |->ui
   |   |   |->openadmin
   |->test
frontend
   |->tone-edu (test with js)
   |   |->tone-test.js
   |->three-edu (test with js)
   |   |->three-test.js
   |->apex-charts (test with js)
   |   |->apex-charts-test.js
   |->styles (all the css defined)
   |   |->my-defined.css.css
   |->src (empty)
   |->generated
   |   |->vaadin.ts
   |->font-awesome
   |   |->webfonts, svgs, sprites, scss, metadata, less, js, css..
gradle.properties
build.gradle


44. Using Gradle. The starting project from Vaadin (2). Adjusting the buid.gradle file

 1. The build.gradle file

Here is the generated file with some add-ons for:
  • using Lombok facilities to reduce boilerplate
  • migrating from javax to Jakarta

// New in the Vaadin starting project version 19+
buildscript {
    repositories {
        maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
    }
}

plugins {
    id 'war'                                 //Generate a ".war" file
    id 'org.gretty' version '3.0.4'
    id 'com.vaadin' version '20.0.0.alpha6' '20.0.6' //Change
}

defaultTasks("clean", "build")

repositories {
    mavenCentral()
    maven { url = "https://maven.vaadin.com/vaadin-addons" }
    jcenter() // jcenter is deprecated, however the Gretty plugin still uses stuff from jcenter: https://github.com/gretty-gradle-plugin/gretty/issues/192
}

// Optional versioning and output folder
project.war.destinationDirectory = file("$rootDir/../mytargets")  
project.archivesBaseName = 'p-aevaadin' 
project.version = '2.0'

// For enabling the generation of the ".war" file 
// This entry is Not generated in the starting-project generation 
// Usually used for production
/*
war {
	enabled = true
}
*/

gretty {
    contextPath = "/"  // it points to https://localhost:8080/
    servletContainer = "jetty9.4"
}

// The following pnpmEnable = true is not needed as pnpm is used by default,
// this is just an example of how to configure the Gradle Vaadin Plugin:
// for more configuraion options please see: https://vaadin.com/docs/latest/guide/start/gradle/#all-options
vaadin {
    //pnpmEnable = true
    //productionMode = true  //Not included in the starting-project generation 
    optimizeBundle= "true" //Change
}
dependencies { implementation enforcedPlatform("com.vaadin:vaadin-bom:$vaadinVersion") // Vaadin //implementation("com.vaadin:vaadin-core")
    implementation("com.vaadin:vaadin")       //Change
    implementation("com.vaadin:vaadin-cdi")   //Change 

    //Use only or jakarta.servet or jakarta.platform but not both at the same time --> genarate errors : The package jakarta.mail is accessible from more than one module: <unnamed>, jakarta.mail
//providedCompile "javax.servlet:javax.servlet-api:3.1.0" //generated by starting-project providedCompile "jakarta.servlet:jakarta.servlet-api:5.0.0" //replace javax by jakarta !!!!!
    // logging
    // currently we are logging through the SLF4J API to SLF4J-Simple. See src/main/resources/simplelogger.properties file for the logger configuration
    implementation "org.slf4j:slf4j-simple:1.7.30"
    
    //=============LOMBOK BEGIN ============================
    // Not generated by the Vaadin starting-project
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
	
    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
    //=============LOMBOK END ==============================


    //=============MY PERSDONAL DEPENDENCIES============================
    / This dependency is for local jars in the folder mylibs
    //implementation files(
    api files(
    	'../mytargets/a-annotations-1.0.jar', 
    	'../mytargets/a-basic-utils-1.0.jar', 
    	'../mytargets/a-report-utils-1.0.jar',
    	'../mytargets/b-base-control-model-1.0.jar', 
    	'../mytargets/b-other-utils-1.0.jar',
    	'../mytargets/c-dao-1.0.jar',
    	'../mytargets/c-model-aytos-1.0.jar',
    	'../mytargets/c-model-gexflow-1.0.jar',
    	'../mytargets/c-vaadin-basic-1.0.jar' )      
    
    implementation "org.jboss.weld.servlet:weld-servlet-shaded:3.1.7.Final"
    
    implementation "org.javassist:javassist:3.27.0-GA"
    
    /* HIbernate */
    implementation "org.hibernate:hibernate-core:5.4.31.Final"
    implementation "org.hibernate:hibernate-envers:5.4.31.Final"
    implementation "org.hibernate:hibernate-validator:7.0.1.Final" 
    
    /*DB Drivers */
    runtimeOnly "com.h2database:h2:1.4.200"
    implementation "org.postgresql:postgresql:42.2.20"
    implementation "net.sourceforge.jtds:jtds:1.3.1"
    
    /* Apache CMIS */
    implementation "org.apache.chemistry.opencmis:chemistry-opencmis-client-impl:1.1.0"
    
    /* JASPER REPORTS */
    implementation "net.sf.jasperreports:jasperreports:6.16.0"
    /* IText VELL pero el vol jasper reports*/
    implementation "com.lowagie:itext:2.1.7"
    implementation "com.itextpdf:itext7-core:7.1.15"  //Falta "type pom" ?????
    
    
    providedCompile "jakarta.activation:jakarta.activation-api:2.0.1"
    
    implementation "com.sun.activation:jakarta.activation:2.0.1"
    //=============MY PERSDONAL DEPENDENCIES END============================

    
}


2. Run in Tomcat

  • Create the Tomcat 9 server, (using for instance the Servers Window)
  • Make sure Jetty is not running (press any key in the Console window and click the red square button if active)
  • Right-Click the project Run As-> Run On Server
  • Wait a moment and it works in
http://localhost:8080/VaadinGradle02/

IMPORTANT: The context is now VaadinGradle02 and not "/" as in jetty

3. Create the war file


1. Uncomment these lines:  (Should be commented!!)

    war {
       enabled = true
  }

and uncomment this one too.

   productionmode = true  (If you do not choose the correct version, the production of the war may fail!!)
If you don't uncomment the line of the "production mode=true", the generated war will only work in the computer you have developed the war, as the war is able to find the source code for debugging, but the war will be looking for the source code if you deploy it in another computer and it will stop execution!

2.  In the Gradle Tasks window, open the build folder and double-click the war task

3. Now the war file is in the build/libs folder



4. If you have choosed the option project.war.destinationDirectory = file("$rootDir/../mytargets")
then the output will be in mytargets directory!
 

martes, 11 de mayo de 2021

43. Using Gradle. The starting project from Vaadin (1)

This super-useful Vaadin guide is applied. Eclipse is used. These are the  main steps:

1. Create a Vaadin 19+ Gradle Project

The starter project is in https://github.com/vaadin/base-starter-gradle

Click in the branches to select master branch


Click in the master branch


Verify that the master branch is selected and download the project


Download ZIP



Now open the zip and copy the "base-starter-gradle-master" folder to an Eclipse Workspace, and change the name for instance to VaadinGradle02


Now from Eclipse click in File->Import->Gradle(folder)->Existing Gradle Project

You get a welcome window


Click Next



Select  Gradle 6.6 Gradle 7.1.1 and a jdk15 compatible and click Next


Now in the last window click Finish.


and in the Project Explorer you can see:


2. Verify the Java version


Now you should change the java version if it is not 15 (in this case it is java 13)

In the Project Explorer, right-click the project and in Properties select Java BUild Path. In my case it points Java version 13


Click on the JRE line and click Edit.


Change all to Java v15


 

then click on Apply and Close Button


3. Compile and Execute the project

1. Right-click on the project and select Gradle -> Refresh Gradle Project

2. Optionally in the Gradle Tasks window open the build folder and double click the build task. This task, although is not necessary, may show possible errors. 


3. In the Gradle Tasks window open the gretty folder and double click in the appRun task


4. After a while open a browser and point to http://localhost:8080/  and here is the result


5. To stop the server, goto to the Console window in Eclipse and press any key

4. Run on Tomcat (problems with gretty version >3.04)

1. Make sure you have installed a Tomcat 9 in the servers window

2. In the Gradle Tasks window open the build folder and double click the build task.

3. Right-click the project and Run AS -> Run on Server 

4. Open a Chrome tab and point to http://localhost:8080/VaadinGradle02/

5. Solving problems (Vaadin 22.0.4)

1. Add procutionMode = false and optimizedBundle = true to the vaadin section (lines 30-31)

2. Delete file settings.gradle and change line 11 as shown

3. Line 39-40 migrate from "javax" to "jakarta" packages



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
buildscript {
    repositories {
        maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
        maven { url "https://plugins.gradle.org/m2/" }
    }
}

plugins {
    id 'war'
    id 'org.gretty' version '3.0.6'
    id 'com.vaadin' version "${vaadinVersion}"
}

defaultTasks("build")

repositories {
    mavenCentral()
}

gretty {
    contextPath = "/"
    servletContainer = "jetty9.4"
}

// The following pnpmEnable = true is not needed as pnpm is used by default,
// this is just an example of how to configure the Gradle Vaadin Plugin:
// for more configuraion options please see: https://vaadin.com/docs/latest/guide/start/gradle/#all-options
vaadin {
    pnpmEnable = true
    productionMode = false  //1.Ximo
    optimizeBundle = true   //2.Ximo
}

dependencies {
    implementation enforcedPlatform("com.vaadin:vaadin-bom:$vaadinVersion")

    // Vaadin
    implementation("com.vaadin:vaadin-core")
    //providedCompile "javax.servlet:javax.servlet-api:3.1.0" //3.a.Ximo
    compileOnly 'jakarta.servlet:jakarta.servlet-api:5.0.0'   //3.b.Ximo
    // logging
    // currently we are logging through the SLF4J API to SLF4J-Simple. See src/main/resources/simplelogger.properties file for the logger configuration
    implementation "org.slf4j:slf4j-simple:1.7.30"
}

viernes, 23 de abril de 2021

42. Vaadin store additional info in a component using attributes. Grid editor disable components using the stored info in attribute

 0. Introduction

Sometimes we want to disable a component from the grid editor. If the component has information that informs that it should be disabled, then most of the work is done

Most of the code is based on Vaadin grid editor tutorial

Let's see how

  • create a new attribute in the component and store info in this attribute 
  • after invoking "grid.getEditor().editItem(record);" locate the component, read the attribute and if the attribute matches some conditions, then disable the component



1. Let's create the grid and assign a list of records

Grid<Person> grid = new Grid<>();
List<Person> persons = getItems();
grid.setItems(persons);


2. Create a column for the desired field (for instance firstName)

Grid.Column<Person> firstNameColumn =
    grid.addColumn(Person::getFirstName)
       .setHeader("First Name");


3. Create a binder for the Person class

Binder<Person> binder = new Binder<>(Person.class);


4. Extract the grid editor and set this binder

Editor<Person> editor = grid.getEditor();
editor.setBinder(binder);
editor.setBuffered(true);


5. Create a component for instance a TexField for that field

TextField firstNameField = new TextField();


6. Bind the component to the field of the class

binder.bind(firstNameField, "firstName");


7. Optional you can create a new column for storing the buttons Save and Cancel

Grid.Column<Person> editorColumn = grid.addComponentColumn(person ->  {
    Button edit = new Button("Edit");
    edit.addClassName("edit");
    edit.addClickListener(e -> {
        editor.editItem(person);
        firstNameField.focus();
    });
    edit.setEnabled(!editor.isOpen());
    editButtons.add(edit);
    return edit;
});


8. Create a new attribute that indicates that this element cannot be enabled for instance "canenable"

firstNameField.getElement().setAttribute("canenable", "FALSE");


9. when invoking the editor, detect if this attribute is present and disable the component

grid.getEditor().editItem(event.getItem()); 
   //or grid.getEditor().editItem(aPerson)

String canEnable="TRUE";

Element elem =firstNameField.getElement();
if (elem.hasAttribute("canenable"))  
    canEnable=elem.getAttribute("caneable").trim();
if (canEnable.equalsIgnoreCase("FALSE") 
    firstNameField.setEnabled(false);
else firstNameField.setEnabled(true);



10. Now this component is disabled for editing!