Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 'tomcat-war' not found in root project #2596

Closed
amirhossein320 opened this issue Sep 6, 2021 · 5 comments
Closed

Project 'tomcat-war' not found in root project #2596

amirhossein320 opened this issue Sep 6, 2021 · 5 comments

Comments

@amirhossein320
Copy link

amirhossein320 commented Sep 6, 2021

Hi, I receive below error when run app grrety tomcat war (./gradlew :tomcat-war:run)

org.gradle.execution.taskpath.ProjectFinderByTaskPath$ProjectLookupException: Project 'tomcat-war' not found in root project 'ktor-sample'.

application.kt

fun Application.module(testing: Boolean = false) {
    routing {
        get{
            call.respond("Hello World")
        }
    }
}

web.app

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
   <servlet>
        <display-name>KtorServlet</display-name>
        <servlet-name>KtorServlet</servlet-name>
        <servlet-class>io.ktor.server.servlet.ServletApplicationEngine</servlet-class>
        <init-param>
            <param-name>io.ktor.ktor.config</param-name>
            <param-value>application.conf</param-value>
        </init-param>
        <async-supported>true</async-supported>
    </servlet>
<servlet-mapping>
        <servlet-name>KtorServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

application.conf

ktor{
    deployment {
        port = 8080
    }
    application{
        modules = [
        com.example.ApplicationKt.module
        ]
    }
}

build.gardle.kts

import java.net.InetAddress.getByName
val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project

plugins {
    application
    kotlin("jvm") version "1.5.30"
    id("org.jetbrains.kotlin.plugin.serialization") version "1.5.30"
    id("org.gretty") version "3.0.6"
    id("war")
}
group = "com.example"
version = "0.0.1"

afterEvaluate {
    tasks.getByName("run") {
        dependsOn("appRun")
    }
}
application {
    mainClass.set("com.example.ApplicationKt")
}
gretty {
    servletContainer = "tomcat9"
    contextPath = "/"
    logbackConfigFile = "src/main/resources/logback.xml"
}
repositories {
    mavenCentral()
}
dependencies {
    implementation("io.ktor:ktor-server-core:$ktor_version")
    implementation("io.ktor:ktor-auth:$ktor_version")
    implementation("io.ktor:ktor-auth-jwt:$ktor_version")
    implementation("io.ktor:ktor-server-host-common:$ktor_version")
    implementation("io.ktor:ktor-serialization:$ktor_version")
    implementation("io.ktor:ktor-server-netty:$ktor_version")
    implementation("io.ktor:ktor-server-tomcat:$ktor_version")
    implementation("ch.qos.logback:logback-classic:$logback_version")
    testImplementation("io.ktor:ktor-server-tests:$ktor_version")
    testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlin_version")
    implementation("io.ktor:ktor-server-servlet:$ktor_version")
}
@Stexxe
Copy link
Contributor

Stexxe commented Sep 6, 2021

@amirhossein320 If you took code from https://github.com/ktorio/ktor-documentation/tree/main/codeSnippets/snippets/tomcat-war then you should have a Gradle subproject named tomcat-war to run it this way, otherwise just run it via ./gradlew run.

@amirhossein320
Copy link
Author

amirhossein320 commented Sep 6, 2021

@amirhossein320 If you took code from https://github.com/ktorio/ktor-documentation/tree/main/codeSnippets/snippets/tomcat-war then you should have a Gradle subproject named tomcat-war to run it this way, otherwise just run it via ./gradlew run.

I watched it. but im begginer and i dont know how create gardle subproject.
please help me to solve it

@Stexxe
Copy link
Contributor

Stexxe commented Sep 6, 2021

I suggest reading https://docs.gradle.org/current/userguide/multi_project_builds.html but you don't need to have a subproject in this case so just run it via ./gradlew run.

@amirhossein320
Copy link
Author

I suggest reading https://docs.gradle.org/current/userguide/multi_project_builds.html but you don't need to have a subproject in this case so just run it via ./gradlew run.

thank you i solve the problem of subproject but now i receive the error about not found task run.
in your sample project use groovy gradle but i use gardle and cant convert run task to it

@Stexxe
Copy link
Contributor

Stexxe commented Sep 8, 2021

If you use the org.gretty Gradle plugin then you can run your application via ./gradlew tomcatStart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants