#Why cant i open a JAR?
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @slender ridge! Please use
/closeor theClose Postbutton 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.
Where do you got that jar from?
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
i built it
Well, you need to build it different. How do you build it? Maven?
I just compiled it
And took the JAR
With Maven
you could use a maven plugin for building the jar correctly.
mvn package on it's own isn't going to make it executable.
check out maven-assembly-plugin (https://maven.apache.org/plugins/maven-assembly-plugin/)
Is this a plugin
yes
go to the usage page for details (https://maven.apache.org/plugins/maven-assembly-plugin/usage.html)
Do i need to install it from my IDE or its default plugin
you add it to your pom.xml
if you don't know how plugins work, I suggest learning about that first.
well do you have a pom.xml?
Yep
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
Why is it inside of build section
because that's the rules lol
I didnt understand <descriptorRefs>
I understand the other ones but not this one
are you looking for a justification as to why it's there?
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
Why console responds me like this when i use mvn
try it
show your manifest tags
so can you show that class?
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();
}
}```
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
package com.example.currencytranslator;
public class Launcher {
public static void main(String[] args) {
CurrencyTranslator.main(args);
}
}```
like that?
yes
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
run ./mvnw clean package and try again
yes
i do it like that but still didnt work
<?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>```
I don't see anything wrong there. if you're up to sending the entire codebase I can look at it
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.
It is this except pom is old
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
Intellij ide
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?
yep
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?
That is the old one i didnt even use maven to compile it i just was up to run it via IDE
that would make more sense
so you use maven to compile your java files?
has this happened before?
or is this the first time
No i somehow was able to make it executable one time but i copy pasted it and dont remember when i did it
i moslty used it for dependencies
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
i tried it
the main class should be similar to Main Class: yourcalsspath
sorry, I meant MainClass
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?
yep
no checked
is shading still available on maven?
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
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
I'm going to send a pull request
@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
I created a working fork
also it may require a few more things from maven
wait a second, that t in translator is also supposed to be Uppercase
but seriously, merge my fork and you good.
wdym
where were you limpeex?
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
how do i do that
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.
i sent
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.
Did you fix the project?
can you try to do it
it still didnt work for me
what did you do exactly?
opened the project and did clean and package
and then java -jar <file>
from ide terminal
what is the error?
make sure you actually pulled from the remote repository
I updated the remote repository
It says unable to access jarfile
nope
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
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
yep you solved it
so what was the problem?
wait lemme try it from cmd
yep i was in the wrong directory
well, YAY!!!!! ya figured it out
but how am i going to open it up by double click
well that is an executable jar file
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
wdym newfile
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?
yeah it works but how do i open it by double clicking
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!
Here is link: https://www.youtube.com/watch?v=jKlyHG-zbjk&t=382s
Java executable jar
#java #executable #jar
0:57 Eclipse .jar
2:25 IntelliJ .jar
3:47 create an icon (.ico)
5:25 executable wrapper
Create an executable jar with Eclipse IDE
- Right click on Java project (pick a project with a GUI)
- Export
- Java , Runnable Jar file
- At Launch configuration selec...
it talks everything about java executable jar
this is what you are talking about
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.
yeah
Thank you both for helping and your time
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
💤 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.