Is it possible to use external Java libraries with out any traditional IDE such as Eclipse or Netbeans?



What if you have deleted some files and your beloved java IDE got broken! Reinstalling didn’t do anything in resolving the problem. So, what to do now? How you can use external java libraries like javafx? If you are in such a problem or just curious enough to know how you can use these libraries without eclipse or netbeans, then this blog may help you figuring it out.

I use Visual Studio Code for coding purpose, and don’t want to use any ide for java because I am accustomed to it. So I searched a little bit and came up with this solution. In this blog, I am using VSCode as a code editor and javafx as the external library.

At first grab your external library from the internet. If you’re looking for the javafx library head over to https://gluonhq.com/products/javafx/ , download the zip file and extract it and copy the folder to the project folder. 20% of the work is done. You can write the java programs now.






After writing the program, the main problem is to compile and run the java program. Only writing “javac test.java” and “java test” is not enough to run the java program. The ides make the compiling and running operation easy for us, but as we are not using any kind of IDE then we have to do the work manually.

Before compiling the program you have to make the compiler know where the javafx files are. So for that you have to set a environment variable containing the path of the javafx files. You can also make another environment variable which will specify where the class files will be stored. To set the javafx environment variable in linux, fire up a terminal and write-
“export SOURCE=/path/to/the/required/jar-files”, on windows, start the command prompt and write-
“set SOURCE=/path/to/the/required/jar-files;”. Similarly you can set the destination path for your program like-
“ export DEST=/path/to/the/destination/folder”. 


 



After that you need to compile the code and for this you need to write-
“javac -d $DEST --module-path $SOURCE --add-modules jarfile_names_without_extension test.java” and booyah!!! your code is compiled and the classfiles are stored in the destination folder.  Here the flag ‘-d’ refers to the destination folder, “--module-path” specifies the path where the external jar files are stored and “--add-modules” adds the required modules to the program. The IDEs do all this stuff by its own, here we only did the IDEs job manually.
Now you need to run the program, so for that , you have to give the following command to the same teminal-
“java -cp $DEST --module-path $SOURCE --add-modules jarfile_names_without_extension test”.

    To automate all this stuff you can create a .sh file(for linux) or a .bat file(for windows) and put all the commands in it according to your need.







    Hope this method will work for you. If you have any problem following the steps then head over to this youtube video- Video. Happy coding...

Comments

Post a Comment

Popular posts from this blog

Linux: Is this the future?

CAN PYTHON REPLACE C/C++ FOR PROGRAMMING THE BAREBONE HARDWARE?