Error with an applet in an Executable Jar in eclipse - java

I want to create an executable jar in eclipse. I tried the option that said create executable jar but it didn't let me. Then I tried creating a normal jar file with a manifest like this:
Main-Class: Game.Game
Class-Path: AppletSource.jar
Here, the executable class is an applet (not JApplet) inside the package Game and a class called Game.class. It uses a package called AppletSource.jar. When I create it, it does not run. It says it failed to load the Main-Class manifest atribute. The AppletSource.jar is in there. Did I miss anything? and is the Main-Class wrote like that if it is inside a package?
PS: I added a main method to the Game class and now it gives me noclassdefounderror. It cant find the AppletSource.jar

Related

Error: Could not find or load main class when trying to run jar file

I'm trying to create a JAR file of my Java code. There are four classes - A.java, B.java, C.java, and D.java. A.java has the main method. These are in a folder called src, and my manifest file is outside of src, and all of my .class files are in bin which is inside src. I created a MANIFEST.MF with the following contents:
Manifest-Version: 1.0
Main-Class: src/A
I then use the command jar cmf MANIFEST.MF A.jar src/bin/*.class src/GraphFile.txt src/ProblemA.txt src/ProblemB.txt (there are a few text files I need to include as well in my JAR file). Then, when I run java -jar A.jar ProblemA.txt GraphFile.txt (note that ProblemA.txt and GraphFile.txt are input files that my program accepts and uses), I get the following error:
Error: Could not find or load main class src.A
Caused by: java.lang.ClassNotFoundException: src.A
Can anyone explain what I am doing wrong or any steps I am missing? Unfortunately, I cannot post the actual code because this is for a class project, but I just need to get it compiled into a JAR file for submission! Thanks for any help.

Failed to generate JAR file using Intellij

I have created a jar in path xxx/IdeaProjects/xxx/out/artifacts/abc_jar.
When I run it using java -jar, I get
Could not find or load main class ...
I have moved the mainfest file to xxx/IdeaProjects/xxx/src/main/resources/META-INF/MANIFEST.MF
and main class is com.rh.xxx.Application, but still getting
Could not find or load main class...
Set the Start-Class attribute value in MANIFEST.MF file with the fully qualified java class. Verify the same in the generated jar file after the jar is created.
Please refer below, here starter class is the one has main method.
Content of, META-INF/MANIFEST.MF
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.mycompany.project.MyApplication
Refer https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html#executable-jar-launcher-manifest for more info.

No main manifest attribute, jar file, Applet

When trying to open my exported project (jar file) I get an error message
No main manifest attribute, in file.jar.
My project is basically a simple class extended by Applet, but the file won't open.
My java is up to date and I've tried using the line in cmd
java -jar file.jar
in order to open it, but it still doesn't work.
What is the reason that the main class isn't recognized?
Thanks for the help!
Create a manifest file like this (manifest.mf)
Main-class: start.HelloWorld
Class-Path: /pathToYourExternalJars/XXXXX.jar /pathToYourExternalJars/XXXXX.jar
Here 'Main-class' is the starting point of your application (simply class which contains main method ) & 'Class-path' is for external jars which are included in your application (Optional)

Cannot create executable jar from Java Swing app successfully

I have made a Java Swing application and now I want to export it as an executable jar file. I have created the app in Eclipse, and it has the following structure :
where folder mysqlconnector contains also a jar file. So first I tried following the instructions in this link and created seo.jar, but when I try to execute it from the terminal by java -jar seo.jar I get an error :
Error: Could not find file connectionprops.properties
As the screenshot shows, I tried putting connectionprops.properties in main package, but the same problem remains.
Then I tried making a manifest file named manifest.mf with contents :
Main-Class: bin.main.MainClass //also tried Main-Class: MainClass
as the structure of my project is :
seo --> bin --> main --> MainClass.class
I placed the manifest.mf in folder seo and I gave the following command in the terminal :
jar -cvfm seo.jar manifest.mf *
but again when executing it from the terminal by java -jar seo.jar I get an error :
Error: Could not find or load main class bin.main.MainClass
What am I doing wrong? Should I change something in my project structure? Is there a problem that I have other jar files inside my project? How can I create the executable jar and execute it successfully?
The Manifest Main-Class attribute needs to receive the package path to your Main class. It doesn't matter what the structure of the project looks like, what matters is the fully qualified package name that you have inside the src/ folder. So in this case, main.MainClass is what you should write there.
Also, if you receive other errors when trying to read the connectionprops.properties in your program, try to open the file using
someObject.getClass().getResourceAsStream("connectionprops.properties")
bin.main is not a package name. You can't add this to manifest.mf.
You should add the package name only if you have the main class in the package. If your package is default then put only the main class.
Main-Class: MainClass

Finding the Main Class

I have my first application written in Netbeans, with supporting libraries. After building the project, the file NetbeansProjects/PDF/dist/PDF.jar runs fine.
I'm ultimately trying to build a OSX app, but think(?) that the first step is to bundle the PDF.jar and the /lib/*.jar files together.
To this end, I'm using JarSplice, but can't work out how set the Main Class. I think it should be found in the manifest.mf file, but it doesn't seem to contain anything. JarSplice requests:
Enter your applications main class file below, complete with any packages that it maybe in.
E.g: my package.someotherpackage.MainClass
Adding System.out.println(main.getClassName()); to my main method gives me "PDF" in the output window of Netbeans.
Can someone tell me how I go about finding the main class, and ideally, because I'm an idiot, exactly what to input into as the main class into JarSplice?
It depends were you put your main class when developing.
Try the class name that contains your main method, if you put your main method in Test.java then put;Test
If your main class is nested in a package then put something like org.package.Test
Once you export your .jar open up the Manifest file and next to Main-Class: should have the main class, just copy and paste

Categories

Resources