So I wrote a project in Eclipse and when I click on the green run button it works fine. When I export it into a jar and I double click on it a quick command prompt appears saying "cannot find or load main class...". I tried everything. I tried renaming registry keys, reinstalling java, changing environment variables and of course turning it on and off again. I read all the other threads on stack and tried everything they suggested. Here is my Manifest file:
Manifest-Version: 1.0
Class-Path: .
Main-Class: main.Main
My Main class is in a package called main.
I'd like to suggest to change the package name into something other than main.
don't forget to make a run configuration, which specifies the name of your main class.
package all the related other jar files into the same package.
run the executable.jar as java -jar YourExecutable.Jar
And if it does not solve your problem, just see my MANIFEST.MF file in my Executable jar file. Maybe it can give you some clue.
Manifest-Version: 1.0
Rsrc-Class-Path: ./ concurrentlinkedhashmap-lru-1.2.jar slf4j-api-1.7.
5.jar org.simpleframework.jar openflowj-0.3.7-SNAPSHOT.jar mongo-java
-driver-2.11.2.jar netty-3.9.0.Final.jar guava-15.0.jar org.restlet.e
xt.jackson.jar logback-classic-1.0.13.jar joda-time-2.2.jar org.codeh
aus.jackson.core.jar org.codehaus.jackson.mapper.jar openflowj-0.3.7-
SNAPSHOT-sources.jar org.restlet.jar logback-core-1.0.13.jar org.rest
let.ext.slf4j.jar org.restlet.ext.simple.jar openflowj-0.3.7-SNAPSHOT
-javadoc.jar
Class-Path: .
Rsrc-Main-Class: etri.sdn.controller.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Related
To start, I have looked at the similar questions posted about this topic. I have not found a solution.
I wish to distribute a small project I have been working on to friends and family. Trouble is I can't expect them all to be able to run .class files. Therefore I am trying to produce a .jar file that I can turn into an .exe file. I am however running into an issue. It complains about missing the main manifest attribute. After some googling, I resolved to try a little tutorial. I am following the tutorial (even downloading the little Hello.jar file), but still I get no main manifest attribute.
As I am running Windows 10, I am using PowerShell to run commands. This is the commands I've run:
PS C:\testJarFraNettet> javac Hello.java
PS C:\testJarFraNettet> jar cmf Hello.mf Hello.jar Hello.class Hello.java
PS C:\testJarFraNettet> java -jar Hello.jar
no main manifest attribute, in Hello.jar
PS C:\testJarFraNettet>
You'll notice I've included the .java file in the .jar as well, just to be sure.
Hello.mf contains:
Manifest-Version: 1.0
Main-Class: Hello
I investigated the .jar file that gets produced. Inside, among the files specified in the command, I find the expected .\META-INF\MANIFEST.MF file with the following content:
Manifest-Version: 1.0
Created-By: 17.0.1 (Eclipse Adoptium)
I've never touched Eclipse (I use VS Code), but I assume this is of no consequence.
Per another article I found online, I edited the file to instead contain what the tutorial tells me it should contain:
Manifest-Version: 1.0
Main-Class: Hello
Still no luck. I've decided against showing my own code, as it needlessly complicates troubleshooting since I get the same error anyways. I still have some hurdles left, such as how to add image files. The project is a GUI based game. But that is an issue for later, I suppose.
Thank you for your time!
jar cfe Hello.jar Hello Hello.class Hello.java
will do it for you. You need to point the -e parameter to the main class so that jar knows how to make it executable. This is easier than making your own manifest
64x Intel processor
Kubuntu 19.04 on Linux 5.0.0-27
OpenJDK 1.8.0_222
In the last hour I have set up my project folder, created scripts for automatic compiling and for back-ups etc...
Finally I got it working, I get the JAR file. The problem is that I can't run it. I know that this is very common problem, but I don't see any compiling errors, mistakes nor typos. I'm totally lost.
Even using java -jar TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint and java -cp TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint show the same error.
Error: Could not find or load main class com.ydsoftware.taskcalender.EntryPoint
My source file structure:
com
ydsoftware
taskcalender
EntryPoint.java (contains main method)
My JAR file structure:
META-INF
MANIFEST.MF
com
ydsoftware
taskcalender
EntryPoint.class (contains main method)
MANIFEST.MF contents (inside the JAR file):
Manifest-Version: 1.0
Created-By: 1.8.0_222 (Private Build)
Main-Class: com.ydsoftware.taskcalender.EntryPoint
Class-Path: lib/MX%20Engine.jar
/ blank /
/ blank /
Can you try below in CMD or through batch file as per your convenience
Generic:
java -cp your_jar_name.jar package_name.classname
as per your class:
java -cp TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint
SOLVED
The problem was that Class-Path: lib/MX%20Engine.jar was missing because my computer had shut down unexpectably (because our power was cut off for some reason) and the changes to MANIFEST.MF were lost. Didn't even notice.
Still, it should say something along the lines of Class not found or unexcepted token instead of saying Could not find or load main class which made finding the problem harder.
Thank you to everyone who tried to help me!
I had developed a standalone program which don't have any GUI, it's only use in the linux machine(without any GUI). So, i converted my java source code into jar file using the following command
jar cfm hardcoded.jar manifest.txt hardcoded.class
The jar file was successfully created but when i try to execute the jar file in the terminal,i get this error
no main manifest attribute, in hardcoded.jar
Some of the information said that the problem due to the manifest file but i can't figure out where is the root cause because i am very new to java on linux,Some people said that the package also need to include but where can i find my package name?.My manifest file is showed as the following
Manifest-Version: 1.0
Class-Path: ./ commons-logging-1.1.2.jar httpclient-4.5.2.jar htt
pcore-4.4.1.jar java-json.jar java-rt-jar-stubs-1.5.0.jar javax-ssl-1
_1.jar joda-time-2.2.jar
Class-Path: .
Main-Class: hardcoded
As you can see my manifest file, i had some others external library, i know eclipse have the build in function to solve this issue, how i need to solve it in linux environment ?
I've just made a "runnable .jar" (or a normal .jar, where I set off manifest on my own. I tryed both) file from my java app with Eclipse.
When I try to open it by double click, i get this message: "could not find or load main class"
From Command Prompt I can run it with 'java -jar xy.jar'.
Works without any problems.
Can anybody help me?
Make sure your manifest file contains the main-class. Like this.
Main-Class: MyPackage.MyClass
You may want to let eclipse make your manifest just so you can see what it does, then save that manifest file and use it going forward. Also check the class path. You can specify that in the manifest also.
Here's a link to how to set the entry point in the manifest
You may also need to put the classpath in your manifest.
Manifest-Version: 1.0
Class-Path: MyUtils.jar
Created-By: 1.7.0_06 (Oracle Corporation)
That can be found here: Adding classpath to manifest
I'm trying to create a jar with the jar tool.
Using the following command
jar.exe cmfv manifest.txt lol.jar Main.class
This generates a jar with the following manifest:
Manifest-Version: 1.0
Created-By: 1.7.0_03 (Oracle Corporation)
Main-Class: Main
When I run the jar from command line (java -jar lol.jar) it runs fine. But when I double click the jar in my folder it gives an error: "Could not find the main class: Main.Program will exit."
What could be causing this?
After trying some stuff out the Manifest currently looks like this:
Manifest-Version: 1.0
Class-Path: .
Created-By: 1.7.0_03 (Oracle Corporation)
Main-Class: code.Main
The Main class has a package declaration added. Inside the jar the 'code' folder/package is added. Still have the same error though.
You should put your Main class into a package, and adjust your manifest correspondingly. That should solve the problem
You need to put the Main class in your classpath. When you run it from the command line, your current directory is auto-added to your classpath, this is why it works from there. When you double click it, you are not specifying the path to the jar as in the classpath. There are ways to add the class to your classpath in your manifest.
Below is an example of one of my jars. lib is a folder within the jar, com/sample/CommandLineClient.class is my main class.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.5.0_12-b04 (Sun Microsystems Inc.)
Class-Path: lib/args4j-2.0.19.jar lib/axis.jar lib/axis-ant.jar lib/commons-discovery-0.2.jar lib/commons-logging-1.0.4.jar lib/jaxrpc.jar lib/log4j-1.2.8.jar lib/saaj.jar lib/wsdl4j-1.5.1.jar
Main-Class: com.sample.CommandLineClientSysIn
What is the file association with the .jar extensions?
Double click the jar file should make the jar run woth the javaw command.
Try making jar files to be executed by default with javaw.
Also take a look at this: http://www.wikihow.com/Run-a-.Jar-Java-File