Program Tip

Gradle- 주요 매니페스트 속성 없음

programtip 2020. 10. 19. 12:36
반응형

Gradle- 주요 매니페스트 속성 없음


Gradle에서 빌드 된 JAR 파일을 실행할 때 발생하는이 오류로 인해 미쳐 가고 있습니다. 오류는 "no main manifest attribute, in RxJavaDemo.jar"로 표시됩니다. Manifest 속성을 조작하려고했지만 종속성이나 무언가를 추가하는 것을 잊은 것 같습니다. 내가 정확히 뭘 잘못하고 있니?

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'demo.MainDashboard'

dependencies {

    compile files ("H:/Processes/Development/libraries/hikari-cp/HikariCP-2.4.1.jar")
    compile files ("H:/Processes/Development/libraries/controls-fx/controlsfx.jar")
    compile files ("H:/Processes/Development/libraries/database_connections/sqlite-jdbc-3.8.6.jar")
    compile files ("H:/Processes/Development/libraries/guava/guava-18.0.jar")
    compile files ("H:/Processes/Development/libraries/rxjava/rxjava-1.0.12.jar")
    compile files ("H:/Processes/Development/libraries/rxjava-extras/rxjava-extras-0.5.15.jar")
    compile files ("H:/Processes/Development/libraries/rxjavafx/RxJavaFX-1.0.0-RC1-SNAPSHOT.jar")
    compile files ("H:/Processes/Development/libraries/rxjavaguava/rxjava-guava-1.0.3.jar")
    compile files ("H:/Processes/Development/libraries/rxjava-jdbc/rxjava-jdbc-0.6.3.jar")
    compile files ("H:/Processes/Development/libraries/slf4j/slf4j-api-1.7.12.jar")
    compile files ("H:/Processes/Development/libraries/tom-commons/tom-commons.jar")

}

sourceSets {
    main.java.srcDir "src/main/java"
    main.resources.srcDir "src/main/resources"
}

    jar { 
  manifest {
    attributes(
      "Class-Path": configurations.compile.collect { it.getName() }.join(' '))
  }
    from configurations.compile.collect { entry -> zipTree(entry) }
}

다음과 같이 매니페스트 속성을 변경하십시오.

jar {
  manifest {
    attributes(
      'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
      'Main-Class': 'hello.HelloWorld'
    )
  }
}

그리고 단지 변경 'hello.helloWorld''<your packagename>.<the name of your Main class>'(자신의 메인 클래스는 주요 방법이 있습니다 경우). 이 경우 매니페스트에서이 클래스를 가리키는 속성을 만들면 jar가 실행됩니다.


FWIW-다음 jar 작업을 사용하여 모든 컴파일 종속성을 jar 파일로 어셈블하고 위의 권장 사항을 사용하여 클래스 경로를 올바르게 설정했습니다.

apply plugin: 'java-library'

jar {
  manifest {
    attributes(
      'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
      'Main-Class': 'your.main.class.goes.here'
    )
  }

  // You can reference any part of the dependency configurations,
  // and you can have as many from statements as you need
  from configurations.compile  
  // I just copied them into the top of the jar, so it looks like the eclipse exported 
  // runnable jar, but you could designate a lib directory, and reference that in the 
  // classpath as "lib/$it.name" instead of it.getName()
  into ''   
}

참고URL : https://stackoverflow.com/questions/32567167/gradle-no-main-manifest-attribute

반응형