#Why cant i open a JAR?

1 messages · Page 1 of 1 (latest)

cursive wraithBOT
#

This post has been reserved for your question.

Hey @slender ridge! Please use /close or the Close Post button above when your problem is solved. 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.

fair shell
#

Where do you got that jar from?

brazen rover
#

the jar doesnt tell java which class its supposed to run

#

you need to either specify the class manually java -cp CurrencyTranslator.jar the.main.Class or get a jar that is properly set up

slender ridge
fair shell
slender ridge
#

And took the JAR

#

With Maven

fair shell
#

You are using mvn package?

#

What is the class name and package of your Main-Methode?

gray compass
#

mvn package on it's own isn't going to make it executable.

gray compass
#

yes

slender ridge
gray compass
#

you add it to your pom.xml

#

if you don't know how plugins work, I suggest learning about that first.

slender ridge
#

From where

#

I dont understand anything

gray compass
#

well do you have a pom.xml?

slender ridge
#

Yep

gray compass
#

so the usage page walks you through adding the plugin to your pom.xml

#

just read the whole thing and ask any questions if you're stuck

slender ridge
#

Why is it inside of build section

gray compass
#

because that's the rules lol

slender ridge
#

I understand the other ones but not this one

gray compass
#

are you looking for a justification as to why it's there?

slender ridge
#

Yep

#

Is it like the thing which compiles project and dependencies

gray compass
#
 If you want to use one of the prefabricated assembly descriptors, you configure which descriptor to use with the <descriptorRefs>/<descriptorRef> parameter.
#

it's just semantics

#

the <descriptorRef>jar-with-dependencies</descriptorRef> is a "prefabricated assembly descriptor" and you're just using those tags so the plugin knows that

slender ridge
gray compass
#

because you haven't installed maven

#

try the maven wrapper in your project instead

slender ridge
#

So what is the right jar

gray compass
#

try it

slender ridge
#

it gives exception

gray compass
#

show your manifest tags

slender ridge
gray compass
#

so can you show that class?

slender ridge
#
package com.example.currencytranslator;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.IOException;

public class CurrencyTranslator extends Application {
    public static void main(String[] args) {
        launch();
    }
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("mainscreen.fxml"));
        Parent root = loader.load();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.getIcons().add(new Image(String.valueOf(getClass().getResource("icon.png"))));
        scene.getStylesheets().add(getClass().getResource("firstcss.css").toExternalForm());
        Mainscreen screen = loader.getController();
        screen.changeColor();
        stage.setTitle("Currency Conversion");
        stage.setResizable(false);
        stage.show();
    }

}```
gray compass
#

ahh

#

so with JavaFx there is an extra step

#

you need to make a new class with a main method and have that call CurrencyTranslator's main method

#

I usually call it Launcher

#

then that would be your main class

slender ridge
#
package com.example.currencytranslator;

public class Launcher {
    public static void main(String[] args) {
        CurrencyTranslator.main(args);
    }
}```
#

like that?

gray compass
#

yes

slender ridge
#

but didnt work

#

once again

gray compass
#

make sure you updated your pom with this as the new class

#

oh

#

I overlooked the fact you're using the command uncorrectly

#

java -jar [jar-name].jar

#

this I think is still a necessary step though

slender ridge
gray compass
#

run ./mvnw clean package and try again

slender ridge
#

how do install this

gray compass
#

./mvnw

#

the ./ is important

slender ridge
gray compass
#

hmmm

#

well I guess just use your IDE to run the commands

slender ridge
#

yep i did it

#

like that

gray compass
#

yes

slender ridge
#

i do it like that but still didnt work

gray compass
#

the same error?

#

can you show your entire pom.xml file?

slender ridge
#
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>CurrencyTranslator</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>CurrencyTranslator</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.10.0</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>22-ea+11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>22-ea+11</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20240303</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>9</source>
                    <target>9</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <archive>
                            <manifest>
                                <mainClass>com.example.currencytranslator.Launcher</mainClass>
                            </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>
</project>```
gray compass
#

I don't see anything wrong there. if you're up to sending the entire codebase I can look at it

novel warren
#

I have experienced this same error. Many programs can fix this issue, but I can help you. First make sure everything is spelled right. Onetime I misspelling main class by one letter and it failed. How about checking other resources on popular platforms like github/replit for help.

slender ridge
#

It is this except pom is old

novel warren
#

it is really annoying this error, even tryed opening the file my self with replacing it with .zip instead of .jar and debuged the issue, although it still didn't work

#

what program are you using

#

it looks like one by jetbrains or maybe eclipse iDE

slender ridge
#

Intellij ide

novel warren
#

well how are you compiling it?

#

are you using the built in jar executable or doing it manually?

#

also most jars require java -jar YourJar.jar

#

to run it if it is not an executable jar

#

VSCode's RedHat extension for VSCode obviously has a built in java: export to compile it as well

#

and it looks like you are using mvnw?

slender ridge
#

yep

slender ridge
#

clean and package

novel warren
#

I found this: com.example.currencytranslator/com.example.currencytranslator.CurrencyTranslator

#

although the CurrencyTranslator .class or .java does not exist?

#

is this a typo, or is it auto compiled into the folder first?

slender ridge
novel warren
#

that would make more sense

#

so you use maven to compile your java files?

#

has this happened before?

#

or is this the first time

slender ridge
#

No i somehow was able to make it executable one time but i copy pasted it and dont remember when i did it

slender ridge
novel warren
#

how about this

#

this is the only way to debug your code

#

first try to make a duplicate of your jar file

#

to work on

#

rename the extension to .zip

#

every jar file is just a comipled .zip file that is runnable through java

#

go into the MANIFEST.MF in META-INF folder

#

(if it exists)

#

and take a look inside

slender ridge
#

i tried it

novel warren
#

the main class should be similar to Main Class: yourcalsspath

#

sorry, I meant MainClass

slender ridge
#

I think it is about javafx

novel warren
#

question, in any of your code, is there a public static void main(String[] args) {}?

#

because it talks about the main class

#

question, did you test your code and see any typos as well?

slender ridge
#

is shading still available on maven?

novel warren
#

I don't know, I don't keep up with maven too much

#

but if you are using IntelliJ IDE, have you tried using the auto jar compiler

#

it makes it so then you won't have to use the java -jar function

#

and it is runnable like an exe

slender ridge
novel warren
#

question, when comipling, can you provide the code from the manifest.mf

#

most problems occur there like in the image on your post

#

and all other times with the no manifest attribute

#

it most likely is not being referenced correctly or it is not in it's correct place

gray compass
#

I'm going to send a pull request

novel warren
#

@slender ridge , can you provide the exact cmds you use to compile/build/try to run it?

#

it might be caused there

#

I FIGURED OUT A WAY TO FIX THIS!

#

first I improved the pom.xml to be a little cleaner and more accurrate

gray compass
#

I created a working fork

novel warren
#

also it may require a few more things from maven

slender ridge
#

What is this i ddnt get this

gray compass
#

that's for creating an image

#

it's like to create native images

#

not jars

novel warren
#

wait a second, that t in translator is also supposed to be Uppercase

gray compass
#

but seriously, merge my fork and you good.

novel warren
#

man, code is really case sensitive

#

why can't code just be easy!

slender ridge
novel warren
#

where were you limpeex?

gray compass
#

add me to the project so I can create a pull request and you can merge it

#

I configured it for you

#

my username is Carter907

slender ridge
#

how do i do that

gray compass
#
Go to your repository's settings, then to "Manage Access", and click on "Invite teams or people". Enter their GitHub username or email address and send the invitation.
slender ridge
#

i sent

gray compass
#

there I merged it for you

#

now run mvn clean package and run the jar in the target folder

#

I set it to jdk 18 if that's not what you're using. use something different but you have everything you need to create an execuable jar file now.

novel warren
#

Did you fix the project?

slender ridge
#

it still didnt work for me

gray compass
#

what did you do exactly?

slender ridge
#

opened the project and did clean and package

#

and then java -jar <file>

#

from ide terminal

gray compass
#

make sure you actually pulled from the remote repository

#

I updated the remote repository

novel warren
#

I'm back!

#

you guys figure out the issue yet?

slender ridge
slender ridge
novel warren
#

can you show me the error?

#

maybe I can help?

#

it took me a long time to figure mine out by I got through it and this should be easy

#

for me

slender ridge
novel warren
#

well are you in the same dir (directory) as that jarfile

#

I have seen this message before

#

it could also just be you misspelling it

slender ridge
#

ah wait

#

worked

slender ridge
novel warren
#

so what was the problem?

slender ridge
#

wait lemme try it from cmd

novel warren
#

it should work

#

just use the same cmd

#

in the same dir

#

...

#

did it work?

slender ridge
novel warren
#

well, YAY!!!!! ya figured it out

slender ridge
#

but how am i going to open it up by double click

novel warren
#

well that is an executable jar file

slender ridge
novel warren
#

yeah, same error, just try using a .bat file with like (at symbol in emails)echo off (new file) java -jar your file.jar

#

then run the bat, it will run the jar and it will work

#

otherwise, you want it to be directly executed through double-click you may have to use outside sources like launch4j which is completely free and allows icons as well

slender ridge
#

wdym newfile

novel warren
#

I mean new line

#

so like:

#

@echo off

#

java -jar yourfile.jar

#

in that exact order

#

also, a .cmd would work with this and a .sh cmd for this would just be the same thing without @echo off part

#

hope this helps!

#

did it work?

slender ridge
#

yeah it works but how do i open it by double clicking

novel warren
#

well, like I said you will probably have to use launch4j, but I have a tutorial for Intellij IDEA AND IDE and ECLIPSE IDE and how to use launch4j for the executable instead of .jar and have an icon

#

I will find the video and paste the link..... after I find it

#

found it!

#

it talks everything about java executable jar

#

this is what you are talking about

slender ridge
#

Okay thanks let me watch

cursive wraithBOT
# slender ridge Okay thanks let me watch

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.

slender ridge
#

@novel warren

#

@gray compass

novel warren
#

yeah

slender ridge
#

Thank you both for helping and your time

novel warren
#

your welcome!
it was a pleasure!

#

I learned so much along my way!

#

hope it helps!

#

if you have any questions just DM me

#

hey, why not friend request me

#

so I can help you more

cursive wraithBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.