Larissa, as you are compiling in hand, have to take into account some considerations:
1° You write the code in the archives .java
, but before creating the JAR executable you must compile the files .java
in .class
.
2° Create a file indicating to JAVA where its method is public static void main(String[ ] args)
, this file is known as MANIFEST
.
3° After the compilation and creation of the MANIFEST
you can already pack everything in one executable .jar
.
With these considerations in mind, first let’s compile your . java classes into . class.
To do this, by terminal or CMD go to the same level of your folder pacote1
(do not enter in pacote1, just be at the same level as her) and type in the terminal:
javac pacote1/*.java
This command will compile all files with extension .java
that are inside the folder pacote1
, you will see that 2 more files appeared, Classe01.class
and Class02.class
.
Now let’s create the MANIFEST
, still at the same level as your folder pacote1
create a MANIFEST.txt file and within it put the content below:
Main-Class: pacote1.Classe01
Name: pacote1/Classe01.class
Java-Bean: True
Now you just need to run the command below so that your compiled classes and manifest are packaged in a file .jar
.
jar cfm seuArquivo.jar manifest.txt pacote1/*.class
And to test run the command:
java -jar seuArquivo.jar
Note: Doing this compilation by hand is very laborious, since any changes you make in the code will have to compile the classes and generate the .jar
again, except that if you are going to use third-party libraries, you will have to inform them on MANIFEST
, I recommend using an IDE as it already automates this whole process.
Larissa, just so we understand your question, are you trying to compile the classes at hand or are you using an IDE (Netbeans or Eclipse)? Other than that, I imagine the structure of your project is like this, a folder called
pacote1
and inside this folder you have 2 filesClasse01.java
andClasse02.java
, that’s right?– Murilo Portugal
Make sure you are not missing add extension
.java
to the class name at the time it calls the compilerjavac
. Already to run the application in the JVM (commandjava
) that’s not necessary.– Piovezan
@Muriloportugal to try to compile the classes in hand. That’s right.
– Larissa Benevides Vieira
@Piovezan did not say add the extension . java.
– Larissa Benevides Vieira