Got error when running application in Railway: no main manifest attribute, in build/libs/12WeekMethod-plain.jar

huangapple go评论76阅读模式
英文:

Got error when running application in Railway: no main manifest attribute, in build/libs/12WeekMethod-plain.jar

问题

我在尝试在Railway部署我的应用程序时遇到了问题。在本地,应用程序运行正常,但在Railway的部署过程中,我不断遇到以下错误消息:

no main manifest attribute, in build/libs/12WeekMethod-plain.jar

这是我的build.gradle文件内容:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.13'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.mundim'
version = ''

java {
    sourceCompatibility = '17'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-maven-plugin:3.1.1'
    implementation 'org.testng:testng:7.1.0'
    runtimeOnly 'org.postgresql:postgresql'

    // Lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    // Swagger
    implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
    // Security
    implementation 'org.springframework.boot:spring-boot-starter-security:3.1.1'
    // Thymeleaf
    implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.1.1.RELEASE'
    // JJWT
    implementation 'com.auth0:java-jwt:4.2.1'
    // Mail sender
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    // Thymeleaf
    implementation 'org.thymeleaf:thymeleaf:3.1.1.RELEASE'

    // Test
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'com.h2database:h2:2.2.220'
    testImplementation 'junit:junit:4.13.2'
}

tasks.named('test') {
    useJUnitPlatform()
}

希望这有助于解决你的问题。如果需要进一步的帮助,请随时提问。

英文:

`I am encountering an issue while attempting to deploy my application in Railway. Locally, the application runs without any problems. However, during the deployment process in Railway, I keep encountering the following error message:

no main manifest attribute, in build/libs/12WeekMethod-plain.jar

This is my build.gradle:

plugins {
	id 'java'
	id 'org.springframework.boot' version '2.7.13'
	id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.mundim'
version = ''

java {
	sourceCompatibility = '17'
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-maven-plugin:3.1.1'
	implementation 'org.testng:testng:7.1.0'
	runtimeOnly 'org.postgresql:postgresql'

	// Lombok
	compileOnly 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok'
	// Swagger
	implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
	// Security
	implementation 'org.springframework.boot:spring-boot-starter-security:3.1.1'
	// Thymeleaf
	implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.1.1.RELEASE'
	// JJWT
	implementation 'com.auth0:java-jwt:4.2.1'
	// Mail sender
	implementation 'org.springframework.boot:spring-boot-starter-mail'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	// Thymeleaf
	implementation 'org.thymeleaf:thymeleaf:3.1.1.RELEASE'

	// Test
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'com.h2database:h2:2.2.220'
	testImplementation 'junit:junit:4.13.2'
}

tasks.named('test') {
	useJUnitPlatform()
}

答案1

得分: 0

问题在于您的依赖关系混乱。您包含了不兼容的版本,并混合使用来自不同版本框架的模块。在这里,您混合使用了Spring Boot 2.7.x和3.1.x,这永远不会起作用,也不是应该做的事情。

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.13'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.mundim'
version = ''

java {
    sourceCompatibility = '17'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

    implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
    
    runtimeOnly 'org.postgresql:postgresql'

    // Lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    // Swagger
    implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
   
    // JJWT
    implementation 'com.auth0:java-jwt:4.2.1'
    // Mail sender
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    // Test
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'com.h2database:h2:2.2.220'
}

tasks.named('test') {
    useJUnitPlatform()
}
  • 删除了testngjunit的依赖项,因为您似乎正在使用JUnit Jupiter(根据测试设置推断)。
  • spring-boot-starter-*依赖项中删除了版本,以便版本对齐。
  • org.thymeleaf.extras:thymeleaf-extras-springsecurity5中删除了版本,以便使用与Spring Boot管理的兼容版本。
  • spring-boot-starter-thymeleaf替换了Thymeleaf,以获取正确的版本和管理。

有了这些修改,您应该拥有正确和兼容的版本,并且您的应用程序将能够启动。

最后,您应该使用./gradlew build来构建一个JAR文件,而不是使用plain,因为它不包含依赖项。您需要部署由Spring Boot创建的fatjar。

英文:

The problem is your dependencies are a mess. You are including incompatible versions and are mixing modules from different versions of a framework. Here you are mixing Spring Boot 2.7.x and 3.1.x that is never going to work nor is something you should never do.

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.13'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.mundim'
version = ''

java {
    sourceCompatibility = '17'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

    implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
    
    runtimeOnly 'org.postgresql:postgresql'

    // Lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    // Swagger
    implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
   
    // JJWT
    implementation 'com.auth0:java-jwt:4.2.1'
    // Mail sender
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    // Test
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'com.h2database:h2:2.2.220'
}

tasks.named('test') {
    useJUnitPlatform()
}
  • Removed testng and junit dependency as you seem to be using JUnit Jupiter (judging from the test setup).
  • Removed version from the spring-boot-starter-* dependencies so the versions align
  • Removed version from org.thymeleaf.extras:thymeleaf-extras-springsecurity5 so it uses a compatible version (managed by Spring Boot)
  • Replaced Thymeleaf with spring-boot-starter-thymeleaf to get the proper version and management.

With this you should have proper and compatible versions and your application will start.

Finally you should use ./gradlew build to build a jar and not use the plain one as that doesn't include the dpendencies. You need to deploy the fatjar created by Spring Boot.

huangapple
  • 本文由 发表于 2023年7月14日 07:22:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683822.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定