Estoy tratando de generar un jar ejecutable para la API en la que he estado trabajando. Pude depurar localmente usando localhost, pero cuando intento ejecutar el artefacto jar generado desde la línea de comando, aparece el error no main manifest attribute, in api.jar
. He leído sobre las preguntas de SO relacionadas aquí y aquí , pero los cambios que recomendaron parecen no tener ningún efecto. La estructura de mi proyecto está a continuación:
Cuando intento seleccionar la clase principal mientras navego por el asistente de artefactos, puedo resaltar la main
clase, pero el botón Aceptar está desactivado.
Finally, when I try to specify the main class manually in the manifest file by right clicking on the main class name and selecting Copy Reference
and pasting the clipboard value in I get the error that it's an invalid main class:
My actual main class is included below. Any help is appreciated.
package api
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
open class KotlinSpringJpaPostgresqlApplication
fun main(args: Array<String>) {
SpringApplication.run(KotlinSpringJpaPostgresqlApplication::class.java, *args)
}
As a final aside, my code is available here if you want to try and run it locally.
You need to append Kt
with an upper case K
to the filename that holds your main method. This is required because of the way Kotlin compiles to Java Bytecode. The fun main()
function in Kotlin is not attached to any class, but Java always requires a class and does not support classless functions.
Tenga en cuenta que el nombre del archivo es importante aquí (en su pregunta es api.kt). Recomendaría simplemente crear un archivo Main.kt
y mover su función principal allí. Se compilará en una clase MainKt, a la que debe hacer referencia desde su manifiesto.
Esperaría que el proceso de compilación sobrescriba su archivo MANIFEST.MF creado manualmente. ¿Ha descomprimido el archivo jar final y ha inspeccionado que MANIFEST.MF es como esperaba que fuera?
En lugar de escribir el MANIFEST.MF usted mismo, deje que su sistema de compilación lo maneje por usted:
Para el estómago:
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>api.KotlinSpringJpaPostgresqlApplicationKt</mainClass>
</manifest>
</archive>
</configuration>
Para Gradle:
jar {
manifest {
attributes 'Main-Class': 'api.KotlinSpringJpaPostgresqlApplicationKt'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras