Running an eclipse project with imports from the terminal or from a text editor (Solved)

0

I've been trying for 2 days to use JavaC and Javatar just to run an app that is in Eclipse from the console but I have not been successful.

Using these guides link and consulting other responses from how to compile a package java in sublime text 3? I have managed to launch a java file without imports from the sublime and from the console, but when I put it to imports it stops working.

The error:

error: package modelos does not exist
error: cannot find symbol

With javatar, exactly the same thing happens.

When I compile A * .java file that comes alone without importing packages, it works and compiles correctly but when it comes with imports, it stops working and passes the same error, so I suspect that javatar and javaC are not using the directories of classes of the imports.

The question is

What other alternatives do I have to be able to run my Java app from a native terminal or windows? or if this is the case, how can I configure the sublime or any other text editor to do the compilation and run the app?

Solution!

Thanks to sjuan76

Create a bat file with the following instructions. set CLASSPATH=#Aqui la ruta de salida de lo que se va a compilar. javac -d %CLASSPATH% @clases.txt cd %CLASSPATH% java #direccion del fichero a ejecutar.

then that file connect it to the Sublime build config or run it directly from the terminal.

    
asked by David DaviDJ Jose 10.10.2018 в 22:39
source

1 answer

0

The problem is not with the packages, the problem is having multiple files.

When you do javac controladores/ClaseA.java , it will search for the class indicated in import modulos.ClaseB .

But that class is not yet compiled , so it does not find it (or the package).

The solution is to compile all classes at the same time. As per command line it can be cumbersome and even exceed the limits of length of commands, you can create a text file that contains the names of all the classes to be compiled and pass it by indicating it with @ :

Fichero clases.txt:

controladores/ClaseA.java
modulos/ClaseB.java

Compilación: javac @clases.txt

And before you say it, yes, it's a bit cumbersome. But it is that almost nobody uses javac directly, even for command line tools are used as ant or maven .

    
answered by 10.10.2018 / 23:15
source