Why cant i open a JAR?

123 Replies
JavaBot
JavaBotOP2y ago
This post has been reserved for your question.
Hey @lip! 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.
Peter Rader
Peter Rader2y ago
Where do you got that jar from?
0x150
0x1502y ago
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
lip
lip2y ago
i built it
Peter Rader
Peter Rader2y ago
Well, you need to build it different. How do you build it? Maven?
lip
lip2y ago
I just compiled it And took the JAR With Maven
Peter Rader
Peter Rader2y ago
You are using mvn package? What is the class name and package of your Main-Methode?
Carter
Carter2y ago
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/)
lip
lip2y ago
Is this a plugin
Carter
Carter2y ago
lip
lip2y ago
Do i need to install it from my IDE or its default plugin
Carter
Carter2y ago
you add it to your pom.xml if you don't know how plugins work, I suggest learning about that first.
lip
lip2y ago
From where I dont understand anything
Carter
Carter2y ago
well do you have a pom.xml?
lip
lip2y ago
Yep
Carter
Carter2y ago
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
lip
lip2y ago
Why is it inside of build section
Carter
Carter2y ago
because that's the rules lol
lip
lip2y ago
I didnt understand <descriptorRefs> I understand the other ones but not this one
Carter
Carter2y ago
are you looking for a justification as to why it's there?
lip
lip2y ago
Yep Is it like the thing which compiles project and dependencies
Carter
Carter2y ago
If you want to use one of the prefabricated assembly descriptors, you configure which descriptor to use with the <descriptorRefs>/<descriptorRef> parameter.
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
lip
lip2y ago
Why console responds me like this when i use mvn
No description
Carter
Carter2y ago
because you haven't installed maven try the maven wrapper in your project instead
lip
lip2y ago
No description
lip
lip2y ago
So what is the right jar
Carter
Carter2y ago
try it
lip
lip2y ago
it gives exception
lip
lip2y ago
No description
Carter
Carter2y ago
show your manifest tags
lip
lip2y ago
No description
Carter
Carter2y ago
so can you show that class?
lip
lip2y ago
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();
}

}
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();
}

}
Carter
Carter2y ago
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
lip
lip2y ago
package com.example.currencytranslator;

public class Launcher {
public static void main(String[] args) {
CurrencyTranslator.main(args);
}
}
package com.example.currencytranslator;

public class Launcher {
public static void main(String[] args) {
CurrencyTranslator.main(args);
}
}
like that?
Carter
Carter2y ago
yes
lip
lip2y ago
but didnt work once again
Carter
Carter2y ago
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
java -jar [jar-name].jar
this I think is still a necessary step though
lip
lip2y ago
No description
Carter
Carter2y ago
run ./mvnw clean package and try again
lip
lip2y ago
No description
lip
lip2y ago
how do install this
Carter
Carter2y ago
./mvnw the ./ is important
lip
lip2y ago
No description
Carter
Carter2y ago
hmmm well I guess just use your IDE to run the commands
lip
lip2y ago
yep i did it
lip
lip2y ago
No description
lip
lip2y ago
like that
Carter
Carter2y ago
yes
lip
lip2y ago
i do it like that but still didnt work
Carter
Carter2y ago
the same error? can you show your entire pom.xml file?
lip
lip2y ago
<?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>
<?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>
Carter
Carter2y ago
I don't see anything wrong there. if you're up to sending the entire codebase I can look at it
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
GitHub
GitHub - limpeex/Currency-Conversion: An application where you can ...
An application where you can convert three different foreign exchange rates: TRY, USD and EUR. - limpeex/Currency-Conversion
lip
lip2y ago
It is this except pom is old
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
Intellij ide
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
yep with maven clean and package
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
That is the old one i didnt even use maven to compile it i just was up to run it via IDE
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
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
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
i tried it
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
No description
lip
lip2y ago
I think it is about javafx
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
yep no checked is shading still available on maven?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
No description
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Carter
Carter2y ago
I'm going to send a pull request
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Carter
Carter2y ago
I created a working fork
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
No description
lip
lip2y ago
What is this i ddnt get this
Carter
Carter2y ago
that's for creating an image it's like to create native images not jars
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Carter
Carter2y ago
but seriously, merge my fork and you good.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
wdym
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Carter
Carter2y ago
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
lip
lip2y ago
how do i do that
Carter
Carter2y ago
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.
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.
lip
lip2y ago
i sent
Carter
Carter2y ago
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.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
can you try to do it it still didnt work for me
Carter
Carter2y ago
what did you do exactly?
lip
lip2y ago
opened the project and did clean and package and then java -jar <file> from ide terminal
Carter
Carter2y ago
what is the error? make sure you actually pulled from the remote repository I updated the remote repository
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
It says unable to access jarfile nope
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
No description
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
ah wait worked yep you solved it
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
wait lemme try it from cmd
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
yep i was in the wrong directory
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
but how am i going to open it up by double click
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
No description
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
wdym newfile
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
yeah it works but how do i open it by double clicking
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
Okay thanks let me watch
JavaBot
JavaBotOP2y ago
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.
lip
lip2y ago
@KyfStore @Kar.Jar
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
lip
lip2y ago
Thank you both for helping and your time
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBotOP2y ago
💤 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.
💤 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.

Did you find this page helpful?