java.lang.NoClassDefFoundError при вызове Api для Heroku [Gradle Tomcat] - PullRequest
0 голосов
/ 02 апреля 2019

Я конвертирую свой рабочий проект Maven в проект Gradle, пока у меня все работает (веб-страницы обслуживаются, и соединение Websocket работает), только мой API еще не работает и выдает следующую ошибку

WARNING: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
2019-04-02T15:22:56.524386+00:00 app[web.1]: 

MultiException stack 1 of 2
2019-04-02T15:22:56.524388+00:00 app[web.1]: java.lang.NoClassDefFoundError: Could not initialize class controllerV2.WTNFcontroller

MultiException stack 2 of 2
java.lang.IllegalStateException: Unable to perform operation: create on api.MemberResource

Пока я пробовал следующее, но безуспешно: NoClassDefFoundError во время выполнения с Gradle

мой рабочий ПОМ

<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>wtnf</groupId>
    <artifactId>wtnf</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>wtnf</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <org.glassfish.jersey.version>2.28</org.glassfish.jersey.version>
        <org.quartz.version>2.2.1</org.quartz.version>
    </properties>

    <dependencies>
        <!-- ORG.GLASSFISH.JERSEY -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${org.glassfish.jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>${org.glassfish.jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <version>${org.glassfish.jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>${org.glassfish.jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-jaxb</artifactId>
            <version>${org.glassfish.jersey.version}</version>
        </dependency>

        <!-- QUARTZ -->
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>${org.quartz.version}</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz-jobs</artifactId>
            <version>${org.quartz.version}</version>
        </dependency>

        <!-- JDA -->
        <dependency>
            <groupId>net.dv8tion</groupId>
            <artifactId>JDA</artifactId>
            <version>3.8.3_460</version>
            <exclusions>
                <exclusion>
                    <groupId>club.minnced</groupId>
                    <artifactId>opus-java</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>3.11.0</version>
        </dependency>

        <!-- OTHER -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.json</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
            <version>9.0.13</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.mindrot</groupId>
            <artifactId>jbcrypt</artifactId>
            <version>0.4</version>
        </dependency>
        <dependency>
            <groupId>com.thetransactioncompany</groupId>
            <artifactId>cors-filter</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.6</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>jcenter</id>
            <name>jcenter-bintray</name>
            <url>http://jcenter.bintray.com</url>
        </repository>
    </repositories>

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/webapp/META-INF</directory>
                <includes>
                    <include>context.xml</include>
                </includes>
                <targetPath>${project.build.directory}/dependency</targetPath>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/jda/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.github.jsimone</groupId>
                                    <artifactId>webapp-runner</artifactId>
                                    <version>9.0.13.0</version>
                                    <destFileName>webapp-runner.jar</destFileName>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.apache.tomcat</groupId>
                                    <artifactId>tomcat-dbcp</artifactId>
                                    <version>9.0.13</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.postgresql</groupId>
                                    <artifactId>postgresql</artifactId>
                                    <version>9.4.1212</version>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

и рабочий maven procfile:

web: java $JAVA_OPTS -cp "target/dependency/*" webapp.runner.launch.Main --context-xml target/dependency/context.xml --port $PORT target/*.war

мой build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 */

plugins {
    id 'java'
    id 'maven-publish'
    id 'war'
    id "com.bmuschko.tomcat" version "2.5"
}

repositories {
    mavenLocal()
    maven {
        url = 'http://jcenter.bintray.com'
    }

    maven {
        url = 'http://repo.maven.apache.org/maven2'
    }
}

sourceSets {
    main {
        java {
            srcDir projectDir
            include 'src/main/java/**'
            include 'src/jda/java/**'
        }
    }
}

def tomcatVersion = '9.0.13'
def orgGlassfishJerseyVersion = '2.28'
def quartzVersion = '2.2.1'

dependencies {
    compile "org.glassfish.jersey.core:jersey-client:${orgGlassfishJerseyVersion}"
    compile "org.glassfish.jersey.containers:jersey-container-servlet:${orgGlassfishJerseyVersion}"
    compile "org.glassfish.jersey.inject:jersey-hk2:${orgGlassfishJerseyVersion}"
    compile "org.glassfish.jersey.media:jersey-media-json-jackson:${orgGlassfishJerseyVersion}"
    compile "org.glassfish.jersey.media:jersey-media-jaxb:${orgGlassfishJerseyVersion}"
    compile "org.quartz-scheduler:quartz:${quartzVersion}"
    compile "org.quartz-scheduler:quartz-jobs:${quartzVersion}"
    compile 'net.dv8tion:JDA:3.8.3_460'
    compile 'org.slf4j:slf4j-api:1.7.25'
    compile 'com.squareup.okhttp3:okhttp:3.11.0'
    compile 'org.json:json:20180813'
    compile 'org.glassfish:javax.json:1.0.4'
    compile 'org.apache.tomcat:tomcat-dbcp:9.0.13'
    compile 'io.jsonwebtoken:jjwt:0.9.1'
    compile 'org.mindrot:jbcrypt:0.4'
    compile 'com.thetransactioncompany:cors-filter:2.6'
    compile 'org.apache.httpcomponents:httpclient:4.5.6'
    compile 'com.github.jsimone:webapp-runner:9.0.13.0'
    compile 'org.postgresql:postgresql:9.4.1212'

    testCompile 'junit:junit:3.8.1'
    providedCompile 'javax.servlet:javax.servlet-api:4.0.1'

    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
           "org.apache.tomcat.embed:tomcat-embed-logging-juli:9.0.0.M6",
           "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
}

tomcatRun.contextPath = '/'
tomcatRunWar.contextPath = '/'

tomcat {
    httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol'
    ajpProtocol  = 'org.apache.coyote.ajp.AjpNio2Protocol'
    enableSSL = true    
}

group = 'wtnf'
version = '0.0.1-SNAPSHOT'
description = 'wtnf'
sourceCompatibility = '1.8'

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

task stage() {
    dependsOn clean, war
}
war.mustRunAfter clean

task copyToLib(type: Copy) {
    into "$buildDir/server"
    from(configurations.compile) {
        include "webapp-runner*"
    }
}

stage.dependsOn(copyToLib)

и профайл gradle

web: java $JAVA_OPTS -jar build/server/webapp-runner-*.jar build/libs/*.war --port $PORT target/*.war 

Чего мне не хватает? Я пробовал гуглить, но пока не повезло. Заранее спасибо!

...