#project runs in the IDE but not when a jar

92 messages · Page 1 of 1 (latest)

narrow pasture
#

When i compile my project it doesn't run

humble epochBOT
#

This post has been reserved for your question.

Hey @narrow pasture! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

narrow pasture
#

no error no nothing

#

just does nothing

#

when i open teh jar in a java decompiler it shows all the correct files

#

this is also the case for other projects not just this one

#

even tried using cmd to compile it and still doesn't work

#

it used to work though

velvet thistle
#

What is the cylorun file?

#

So that's a folder. Where is your jar file?

#

Are you able run your program by typing "java Main" in your Command Prompt?

narrow pasture
narrow pasture
#

i used to be able to compile shit into jar files but now they don't work

#

i tried cd path to project root

#

and java Main

#

or path to the jar

velvet thistle
#

Open Command Prompt
Make sure it is direct to the same folder as your class files
Type java Main

narrow pasture
#

Error: Could not find or load main class main Caused by: java.lang.ClassNotFoundException: main

sudden crane
narrow pasture
sudden crane
#

how did you build the jar ?

narrow pasture
#

project structure> artifacts> jar from modules with dependencies> all modules, me.cylorun.Main

#

then ok

#

build>build artifacts>build

#

IntelliJ btw

sudden crane
#

what's the name of the jar

narrow pasture
#

shfinder.jar

sudden crane
#

open cmd navigate to the correct folder then type:
java -jar shfinder.jar

#

tell me what the output is

narrow pasture
#

correct folder?

#

being a folder with the jar

#

or the project root

sudden crane
#

correct folder, the folder in which the jar is located. Alternatively provide the full path to the jar

narrow pasture
#

no main manifest attribute, in shFinder.jar

sudden crane
#

you aren't using a build system like maven or gradle, are you ?

narrow pasture
#

im using gradle

#

and groovy

sudden crane
#

then you don't build the jar through intelliJ but through gradle. Gradle should provide the task build->jar

narrow pasture
#

build->jar : The term 'build->jar' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • build->jar
  •   + CategoryInfo          : ObjectNotFound: (build->jar:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
#

uuh 😅

#

maybe im running it in the wrong place

sudden crane
#

did you try running build->jar in your console xD

narrow pasture
#

yes

#

or in the project terminal

#

sorry for being kinda dumb

sudden crane
#

in the top right corner you have a gradle tab

#

I meant that you execute the task in there

narrow pasture
#

oh xD

#

lol

sudden crane
#

alternatively you can run ProjectName [jar] in your console or gradle build jar

narrow pasture
#

ah ok

#

where will the jar file be located?

sudden crane
#

in your build directory

narrow pasture
#

it's not there

sudden crane
#

hmm did the task complete successfully ?

narrow pasture
#

seems like it

#

this is what it says

#

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE

BUILD SUCCESSFUL in 102ms
3 actionable tasks: 3 up-to-date
21:28:04: Execution finished 'jar'.
sudden crane
#

could you share your build.gradle file

narrow pasture
#
    id 'java'
}

group 'me.cylorun'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven {
        url "https://jitpack.io"
      maven { url 'https://maven.izzel.io/releases' }

    }
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
    implementation 'com.github.KaptainWutax:SEED:master-SNAPSHOT'
    implementation 'com.github.KaptainWutax:MathUtils:5531c4a87b0f1bb85d1dab2bdd18ce375400626a'
    implementation 'io.izzel:nbt:1.1.0'


}

test {
    useJUnitPlatform()
}```
sudden crane
#

yeah I figured. You need to add this block and configure it:

jar {
    manifest {
        attributes "Main-Class" : "path.to.Main"
    }
}
narrow pasture
#

oh okay

#

is it in build\libs?

#

because that one still doesn't run

sudden crane
#

yeah its in build/libs

narrow pasture
#

hmmm

#

why does it not run 😭

sudden crane
#

where did you add the jar block ?

narrow pasture
#

at the bottom

sudden crane
#

and you did configure it ?

narrow pasture
#

yeah

sudden crane
#

the jar is compiled and appearing ?

narrow pasture
#

jar { manifest { attributes "Main-Class" : "me.cylorun.Main" }

narrow pasture
sudden crane
#

and what's the output when running in the console

narrow pasture
#

not loading that lib

sudden crane
#

you are trying to bundle the libraries inside the jar

narrow pasture
#

yes

sudden crane
#

... you should have lead with that

narrow pasture
#

oh shit

sudden crane
#

alright inside plugins add
id 'com.github.johnrengelman.shadow' version "7.1.2"
then run the shadowJar task that should have appeared

narrow pasture
#

aight

#

got that done

#

holy shit

#

thank you so much

humble epochBOT
# narrow pasture thank you so much

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

narrow pasture
#

sorry for being kinda dumb regarding this stuff