Failed to deploy app-core to Tomcat 8.5.14 instance Ubuntu

I tried to upload my application to my Tomcat instance today.
When i uploaded App-core i got this error message:


2017-04-24 15:28:27.507 ERROR [localhost-startStop-1] com.haulmont.cuba.core.sys.AppContextLoader - Error initializing application
java.lang.RuntimeException: java.io.FileNotFoundException: /app_home/app-core/work/orm.xml (Fila eller mappa finnes ikke)
	at com.haulmont.cuba.core.sys.persistence.MappingFileCreator.writeDocument(MappingFileCreator.java:213) ~[cuba-core-6.4.2.jar:6.4.2]
	at com.haulmont.cuba.core.sys.persistence.MappingFileCreator.create(MappingFileCreator.java:111) ~[cuba-core-6.4.2.jar:6.4.2]
	at com.haulmont.cuba.core.sys.persistence.PersistenceConfigProcessor.create(PersistenceConfigProcessor.java:108) ~[cuba-core-6.4.2.jar:6.4.2]
	at com.haulmont.cuba.core.sys.AppContextLoader.createPersistenceXml(AppContextLoader.java:70) ~[cuba-core-6.4.2.jar:6.4.2]
	at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_121]
	at com.haulmont.cuba.core.sys.AppContextLoader.beforeInitAppContext(AppContextLoader.java:85) ~[cuba-core-6.4.2.jar:6.4.2]
	at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:70) ~[cuba-global-6.4.2.jar:6.4.2]
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) [catalina.jar:8.5.14]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) [catalina.jar:8.5.14]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.5.14]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752) [catalina.jar:8.5.14]
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728) [catalina.jar:8.5.14]
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) [catalina.jar:8.5.14]
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952) [catalina.jar:8.5.14]
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823) [catalina.jar:8.5.14]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: java.io.FileNotFoundException: /app_home/app-core/work/orm.xml (Fila eller mappa finnes ikke)
	at java.io.FileOutputStream.open0(Native Method) ~[na:1.8.0_121]
	at java.io.FileOutputStream.open(FileOutputStream.java:270) ~[na:1.8.0_121]
	at java.io.FileOutputStream.<init>(FileOutputStream.java:213) ~[na:1.8.0_121]
	at java.io.FileOutputStream.<init>(FileOutputStream.java:162) ~[na:1.8.0_121]
	at com.haulmont.cuba.core.sys.persistence.MappingFileCreator.writeDocument(MappingFileCreator.java:210) ~[cuba-core-6.4.2.jar:6.4.2]
	... 19 common frames omitted
24-Apr-2017 15:28:27.510 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
24-Apr-2017 15:28:27.528 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/app-core] startup failed due to previous errors

Does someone have an idea?

Hi,

It seems that you’ve incorrectly set /app_home location in build.gradle and this directory does not exist.

Well, this is the Application home directory that is given when i select BuildWar in Deployment settings
What can I use instead?

Here is the build.gradle file.
Maby something is missing or wrong.



buildscript {
    ext.cubaVersion = '6.4.2'
    repositories {
        maven {
            url 'https://repo.cuba-platform.com/content/groups/work'
            credentials {
                username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba')
                password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123')
            }
        }
        maven {
            url 'https://repo.cuba-platform.com/content/groups/premium'
            credentials {
                username(rootProject.hasProperty('premiumRepoUser') ? rootProject['premiumRepoUser'] : System.getenv('CUBA_PREMIUM_USER'))
                password(rootProject.hasProperty('premiumRepoPass') ? rootProject['premiumRepoPass'] : System.getenv('CUBA_PREMIUM_PASSWORD'))
            }
        }
    }
    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"

        classpath "com.haulmont.cuba:cuba-global:$cubaVersion"
        classpath "com.haulmont.reports:reports-global:$cubaVersion"
        classpath "com.haulmont.charts:charts-global:$cubaVersion"

        
    }
}

def globalModule = project(':app-global')
def coreModule = project(':app-core')
def guiModule = project(':app-gui')
def webModule = project(':app-web')
def portalModule = project(':app-portal')
def webThemesModule= project(':app-web-themes')

def servletApi = 'org.apache.tomcat:tomcat-servlet-api:8.0.26'


apply(plugin: 'idea')
apply(plugin: 'cuba')

cuba {
    artifact {
        group = 'com.fleetmanager'
        version = '0.1'
        isSnapshot = true
    }
    tomcat {
        dir = "$project.rootDir/deploy/tomcat"
    }
}

def postgres = 'org.postgresql:postgresql:9.4.1212'

configure([globalModule, coreModule, guiModule, webModule, portalModule]) {
    apply(plugin: 'java')
    apply(plugin: 'maven')
    apply(plugin: 'idea')
    apply(plugin: 'cuba')

    dependencies {
        testCompile('junit:junit:4.12')
    }

    task sourceJar(type: Jar) {
        from file('src')
        classifier = 'sources'
    }

    artifacts {
        archives sourceJar
    }
}

configure(globalModule) {
    dependencies {
        compile('com.google.maps:google-maps-services:0.1.19')

    }

    task enhance(type: CubaEnhancing)
    
    
}

configure(coreModule) {

    configurations {
        jdbc
        dbscripts
    }

    dependencies {
        compile(globalModule)
        provided(servletApi)
        jdbc(postgres)
        testRuntime(postgres)

    }

    task cleanConf(description: 'Cleans up conf directory') << {
        def dir = new File(cuba.tomcat.dir, '/conf/app-core')
        if (dir.isDirectory()) {
            ant.delete(includeemptydirs: true) {
                fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
            }
        }
    }

    task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
        appName = 'app-core'
        appJars('app-global', 'app-core')
    }

    task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
        dbms = 'postgres'
        host = 'localhost'
        dbName = 'fleetmanager'
        dbUser = 'cuba'
        dbPassword = '*'
    }

    task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
        dbms = 'postgres'
        host = 'localhost'
        dbName = 'fleetmanager'
        dbUser = 'cuba'
        dbPassword = '*'
    }
}

configure(guiModule) {
    dependencies {
        compile(globalModule)

    }

    task deployConf(type: Copy) {
        from file('src')
        include "com/fleetmanager/**"
        into "$cuba.tomcat.dir/conf/app"
    }
}

configure(webModule) {
    configurations {
        webcontent
    }

    dependencies {
        provided(servletApi)
        compile(guiModule)

    }
    
    task webArchive(type: Zip) {
        from file("$buildDir/web")
        from file('web')
        classifier = 'web'
    }

    artifacts {
        archives webArchive
    }

    task deployConf(type: Copy) {
        from file('src')
        include "com/fleetmanager/**"
        into "$cuba.tomcat.dir/conf/app"
    }

    task clearMessagesCache(type: CubaClearMessagesCache) {
        appName = 'app'
    }
    deployConf.dependsOn clearMessagesCache

    task cleanConf(description: 'Cleans up conf directory') << {
        def dir = new File(cuba.tomcat.dir, '/conf/app')
        if (dir.isDirectory()) {
            ant.delete(includeemptydirs: true) {
                fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
            }
        }
    }

    task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
        appName = 'app'
        appJars('app-global', 'app-gui', 'app-web')
    }
    task buildScssThemes(type: CubaWebScssThemeCreation)
    task deployThemes(type: CubaDeployThemeTask, dependsOn: buildScssThemes)
    assemble.dependsOn buildScssThemes
}



configure(portalModule) {
    dependencies {
        provided(servletApi)
        compile(globalModule)
        
    }

    def webappName = 'app-portal'
    def resourcesDir = "$cuba.tomcat.dir/webapps/$webappName/resources"
    def ftlDir = "$cuba.tomcat.dir/webapps/$webappName/WEB-INF/templates"

    task deploy(dependsOn: assemble, type: CubaDeployment) {
        appName = webappName
        appJars('app-global', 'app-portal')
    }

    task deployStatic() << {
        copy {
            from file('web/resources')
            include '**/*.css'
            include '**/*.js'
            include '**/*.png'
            include '**/*.gif'
            include '**/*.jpg'
            into resourcesDir
        }
        copy {
            from file('web/WEB-INF/templates')
            include '**/*.ftl'
            into ftlDir
        }
    }

    task cleanStatic() << {
        delete resourcesDir
        delete ftlDir
    }

    task webArchive(type: Zip) {
        from file('web')
        from file("$buildDir/web")
        exclude '**/web.xml', '**/app.properties'
        classifier = 'web'
    }

    artifacts {
        archives webArchive
    }
}


configure(webThemesModule) {
    apply(plugin: 'java')
    apply(plugin: 'maven')
    apply(plugin: 'cuba')

    appModuleType = 'web-themes'

    buildDir = file('../build/scss-themes')

    sourceSets {
        main {
            java {
                srcDir '.'
            }
            resources {
                srcDir '.'
            }
        }
    }
}


task undeploy(type: Delete, dependsOn: ':app-web:cleanConf') {
    delete("$cuba.tomcat.dir/shared")
    delete("$cuba.tomcat.dir/webapps/app-core")
    delete("$cuba.tomcat.dir/webapps/app")
    delete("$cuba.tomcat.dir/webapps/app-portal")
}

task restart(dependsOn: ['stop', ':app-core:deploy', ':app-web:deploy', ':app-portal:deploy'], description: 'Redeploys applications and restarts local Tomcat') << {
    ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') {
        not {
            socket(server: 'localhost', port: '8787')
        }
    }
    start.execute()
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.1'
}

apply from: 'extra.gradle'







task buildWar(type: CubaWarBuilding) {
    coreContextXmlPath = 'modules/core/web/META-INF/war-context.xml'
    singleWar = false
    includeContextXml = true
    appProperties = ['cuba.automaticDatabaseUpdate' : true]
    includeJdbcDriver = true
    appHome = './app_home'
}

Your appHome needs to point to the folder that the war file is going to be copied to. For example:

appHome = ‘/home/site/wwwroot/webapps’.

You need appHome to point to the webapps folder that the war file is copied to. Please CUBA team, this is a recurring issue and needs to be better documented in the docs and give a better default value then just ‘app_home’.

I think your default of ‘app_home’ when creating war file is misleading and what causes people to not understand. I have spent hours as a newbie trying to figure this out. It’s a no brainer for people that are experienced but for people that are new, we are assuming the default values being provided are valid … and they are not.

People, ‘app_home’ is a placeholder for where you are specifying the war file is being copied to. It can be absolute or relative but it needs to eventually point to the ‘webapps’ folder.

So if I want to deploy to Tomcat I have to create a folder inside webapps with the name app_home?
And the deployment will copy the app.war and app-core.war to app_home?

If your Tomcat folder is /someuser/tomcat/webapps then appHome should point to /someuser/tomcat/webapps

Your war files should be placed in /someuser/tomcat/webapps and appHome should be set to /someuser/tomcat/webapps

That’s it!

So in my case:
I have installed Tomcat at /opt/tomcat/webapps.
Then appHome shall point to /opt/tomcat/webapps.

Yes.

Good. I hope others also can make use of this topic.
And CUBA-platform team: Please put this information into the documentation.
It will make things easy for other users to.

IanE. To you have any experience with Nginx on Ubuntu and using it to redirect the user to different instances of Tomcat but still come from the same address outside?

Sorry Kjell, I have no experience in this area. You will need to look at the Application Scaling documentation.