#I can't figure out to create a .jar file without having a ClassNotFound Exception
84 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @fervent jolt! Please use
/closeor theClose Postbutton above when you're finished. 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.
what is inside of manifest.mf?
how do you run the jar file?
what is inside the manifest file is :
Main-Class: Derivative.class
with an \n at the end
and the command is :
jar -cvfm work.jar MANIFEST.mf C:\Users\HP\Desktop\Programs\Java\Math\Calculus\cal\out\cal\*.class
and for running the jar file I use:
java -jar work.jar
no need to have .class in name of the main class
maybe you deleted \n?
no
manifest usually has ```
Manifest-Version: 1.0
Main-Class: MainClasName
Main-Class: Derivative
it still give me the error
it's suppose to only have .class file right
with the other classes
it can contain whatever you want
just there should be thesame structure of the packages (directories) with including class files
andMETA-INF dir for maniifest file
and MANIFEST.MF file in it
so I need to to the command out of the package directory
sorry?
so you see in cmd I can be in different directories and since a package is just a folder should I perform the command out of the package directory or inside of it
no
java will be looking for the needed class inside of jar as separate classpath
you run the jar file correctly
just make sure that you have right structure
like ```
- Derivative.class
- META-INF
-- MANIFEST.MF
but command with jar first does I need to have the other class with the main class
if main class uses another specific classes (not a part of standard jre set of classes), then yes, it has to be in the jar file as well
Is Derivative class in a package?
yeah in the package cal with Render
then you need to set it correctly in manifest file:```
Main-Class: Render.Derivative
java will be looking for the main class starting from the root of jar file
so if main class is in ./Render/Derivative.class, then you set the main class in manifest as I wrote above
ah, so cal.Derivative
I try
but still give me an header field error
jar cvfm MANIFEST.txt Derivative.class Render.class look for yourself
oh
manifest.mf, not txt
and, since classes are in packages, you need to add them including packages
jar cvfm work.jar MANIFEST.mf cal.Derivative.class cal.Render.class like this
try this : jar cvfm work.jar cal\MANIFEST.mf cal cal\Derivative.class cal\Render.class
but now there is no manifest attribute
best would be using
jar cfe JarExample.jar cal.Derivative cal/*.class
but there is no manifest
option e automatically creates it and put as main class the second argument
m if you want to copy existing manifest file
but if only thing you need is to specify the main class, e option is better
since it creates manifest itself, and put as main class the class name, that you specify
but the frame is poping out
what frame?
the frame in my program in Render.class
and?
even if there is no error if the frame doesnt appear I can't to do anything
with the program
at the moment, does jar file work? no errors like main class not found or manifest field error etc?
yeah
good, problem is solved, now you know how to create it manually and run it
but the frame
import java.lang.Math;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.*;
public class Derivative
{
public static void main(String[] args){
new Render();
}
}```
it works
in my ide
so they should not be a problem
what did you do
compiled
put in jar as I wrote above
and run
can you write the command please
when you are in project root (suppose it's test directory) you run:```
javac cal/.java
jar cfe my.jar cal.Derivative cal/.class
java -jar my.jar
Yes it works thank you so much
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.
np 😉