-1

I am trying to export my project (classes and resource folder) to a jar file.

The program runs as expected within eclipse but the jar file does not open. I have tried running the jar file from cmd which produces the error message "unable to open jarfile." I have reinstalled JRE and eclipse.

Path to code: E:\Eclipse WS\offbeat\src\com\mania\main

Path to Resource Folder: E:\Eclipse WS\offbeat\src\com\mania\main\beatmaps

1 Answers1

1

Jar filews itself are not runnable out of the box, what you want to do is to make it a runnable jar by putting main class details into a manifest file inside the JAR. Only with the manifest inside it will work, as VM will know which main class to use

If you are using maven, you can use jar plugin to tell it to add manifest entries https://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html

If not using maven, you can tell eclipse to do it: How can I export a runnable jar in Eclipse with a specific manifest file and required library extraction?

And here are the details on manifests, they are super simple text files https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html

maslan
  • 2,078
  • 16
  • 34
  • I apologize if I may be missing something obvious as it's my first time creating a jar file. This is my manifest file currently: `Manifest-Version: 1.0 Class-Path: . Main-Class: com.mania.main.Game` Perhaps using javafx has something to do with this problem... Am I missing something? Thank you for the reply. – Kevin Druciak Jun 07 '19 at 06:37
  • you would neeed to diagnose it by trying to run jar file from the command line - this will produce more meaningful exception. Do java -jar JARNAME – maslan Jun 07 '19 at 08:29