Monday, April 22, 2013

Run Eclipse project in command line

Steps to create a sample project in Eclipse and execute in command line;
  1. Create Eclipse project and compile it. It will create output in bin folder, which will have .class files.
  2. Create a batch file for classpath. In this batch file create set classpaths for all jar files which are used in Eclipse project. Also set classpath to bin folder of eclipse project.
  3. Copy all the required resources in bin folder. In my example, I had to copy "" file in bin folder.
  4. Now you can execute Main class using Java Main Class.
  5. See sample batch file for setting classpath and executing the file.
Sample batch file for ClassPath
SET BaseFolder=C:\Users\Administrator\workspace\MyLearning01\
Set CLASSPATH=%CLASSPATH%;%BaseFolder%bin\;
Set CLASSPATH=%CLASSPATH%;%BaseFolder%lib\MyFirstJar.jar;
Set CLASSPATH=%CLASSPATH%;%BaseFolder%lib\MySecondjar.jar;


Sample batch file for the main class:
java eshu.learning01.MyMainClass


No comments:

Post a Comment