compilation - Execution Java -cp -
i have doubt -cp , when should use it. scenario: have 2 .java, first one:
package autos.tests.paquete;
public class mainautos {
public static void main(string args[]) { int x = integer.parseint(args[0]); respotar objeto1 = new respotar (x); int mostrar = objeto1.repostar(); system.out.println(mostrar); } }
and second one:
package autos.tests.paquete;
public class respotar {
int gasolina; public respotar (int gasolina) { this.gasolina=gasolina; } public int repostar (){ int gasolina = this.gasolina +20; return gasolina; } }
well, @ root directory, , there, have directory: autos/tests/paquete both .java.
so compile: javac autos/tests/paquete/*.java
and execute root directory: java autos.tests.paquete.mainautos 10 , works, here go doubts:
1) execute java -cp . autos.tests.paquete.main autos 10 , behaviour same.
2) move respotar.class auto/tests/paquete directory, compile java autos.tests.paquete.mainautos 10 , works.
3) move mainautos.class auto/tests/paquete directory, compile java autos.tests.paquete.mainautos 10 , says: error: not find or load main class autos.tests.paquete.mainautos
4) compile java -cp . autos.tests.paquete.mainautos (i have .class on current directory compiling, think have use -cp .) , says same: error: not find or load main class autos.tests.paquete.mainautos
thank in advance, hope can enlighten me, regards
java -cp used set libraries such jar file current classpath.
for examples have shown, can in below simple way
from root directory compile java files using below command
javac -d . *.java this created appropriate packages , place class files under them
then run code using command same root location
java autos.tests.paquete.mainautos
Comments
Post a Comment