Colton Idle
02/12/2024, 5:20 PMno main manifest attribute, in build/libs/ktor-starter-0.0.1.jar
Any tips for that? Have no idea what im doing. stackoverflow said to add a fat jar via a gradle task and that didn't work.Aleksei Tirman [JB]
02/12/2024, 6:34 PMColton Idle
02/12/2024, 7:42 PMColton Idle
02/12/2024, 7:43 PMAleksei Tirman [JB]
02/13/2024, 7:30 AMjava -jar ...
command?Colton Idle
02/13/2024, 7:49 AMCasey Brooks
02/13/2024, 9:11 PMktor-starter-0.0.1-all.jar
(note the -all
). The error shown looks like you’re trying to execute the normal jar, not the fat jar.
The normal build process will create a jar file with the project name, but that one only includes your own project’s compiled code and resources. It cannot run on its own with the java -jar
command, though it will able able to be executed through Gradle (./gradlew run
). To run the app on Railway or other hosting services, you need to run the fat jar without Gradle, which bundles all dependences (Ktor, Netty, Serialization, etc.) along with your own code.Colton Idle
02/13/2024, 9:17 PMgradle buildFatJar
and for deploy step, gradle runFatJar
that seems to work, BUT gradle runFatJar won't run unless I have at least a gig of ram seemingly (even for hello world sample).Colton Idle
02/13/2024, 9:17 PMColton Idle
02/13/2024, 9:17 PMCasey Brooks
02/13/2024, 9:18 PMColton Idle
02/13/2024, 9:18 PMCasey Brooks
02/13/2024, 9:19 PMbuildFatJar
and runFatJar
Gradle tasks are provided by the Ktor plugin, so yes it’s inlucded. Just wanted to make sure you were running those and not the typical ./gradlew assemble
Colton Idle
02/13/2024, 9:19 PMYeah, that’s proabbly part of the problem. When you run it like that, you’re going to incur the memory penalty of Gradle along with the server application itself. Gradle is a beast and a memory hog, and you definitely don’t want to have that be part of the deploymentoh really? what would you suggest then (apologies. i literally have 0 exp on server)
Casey Brooks
02/13/2024, 9:20 PMjava -jar build/libs/ktor-starter-0.0.1-all.jar
. This does not use Gradle, but executes the fat jar directly, similar to running a .exe
on WindowsColton Idle
02/13/2024, 9:20 PMCasey Brooks
02/13/2024, 9:21 PMColton Idle
02/13/2024, 9:21 PMColton Idle
02/13/2024, 9:21 PMgradle buildFatJar
? i guess not based on your last messageColton Idle
02/13/2024, 9:22 PMCasey Brooks
02/13/2024, 9:29 PM./gradlew buildFatJar
.
2. The build server uploads the build artifact to another server, and then runs the “start command” there. These servers can often be run with fairly minimal memory and CPU, because the idle server application typically doesn’t consume too much system resources. Memory and CPU usage scales with incoming traffic, not really with the application code. Because of the memory limitations, and because these servers are exposed to the public internet, you don’t want to expose yourself to anything more than is absolutely necessary. Thus, you should execute the build artifact generated in step 1, and not run a Gradle build command. So the run command should be java -jar build/libs/ktor-starter-0.0.1-all.jar
.Colton Idle
02/13/2024, 9:35 PMColton Idle
02/14/2024, 12:12 AMjava -jar myjar.jar
seemed to fix my out of memory issues when simply trying to deploy