Compile and execute Java project from terminal

1

I am trying to compile and run a Java project from the Windows terminal, I have a folder. \ lib with several .jar

To compile I use the following command:

javac -encoding UTF-8 -d. \ bin -cp. \ src. \ src \ game \ Party.java

Compile me without errors But I get an error when executing it with the following instruction:

java -cp. \ bin. \ Game \ Party

I get the error: The main class was not found or loaded. \ Party.java

I also have some .jar in the folder. \ lib, but I do not know how to pass this to the classpath in the compilation, I tried this but it does not work;

javac -encoding UTF-8 -d. \ bin -cp. \ src \ lib. \ src \ game \ Party.java

I appreciate any help.

    
asked by H. Postiga 26.10.2017 в 00:19
source

2 answers

0

What I run from the windows terminal is first download the JDK from the Oracle page Once you have downloaded and installed correctly, proceed to find the installation path for example:     1 | C: \ Program Files \ Java \ jdk1.7.0_02 \ bin

Team - > Right click - > Properties - > Advanced System Configuration - > [Tab] Advanced Options - > Environment Variables We look for the name variable Path, press Edit, in the box shown, we go to the end of the text that is already written and add the following without the quotes: "; C: \ Program Files \ Java \ jdk1.7.0_02 \ bin;"

Once we have added the route, we press OK, then again OK and start a console (cmd) and write javac, we should get something like this:

After compiling your program looking for the path of your folder and indicating the name of the file as it is written, do not forget to put them in. java or depends on the code you want to run

    
answered by 26.10.2017 в 01:35
0

Assuming that src\partida\Partido.java is in the split package.

And you compile it with:

javac -encoding UTF-8 -d .\bin -cp .\src .\src\partida\Partido.java

Then to execute it, you must specify the full class name:

java -cp bin partido.Partido
    
answered by 26.04.2018 в 01:37