Kind of old question I know, but if you want to know command prompt for running Eclipse-based project (i.e the one that Eclipse uses)

  1. Run your project into Eclipse
  2. Goto Debug perspective
  3. (on my screen anyway) Window in top left corner should have a little 'debug' tab.
  4. Right click on name of your project, select Properties at the bottom of drop-down
  5. Click on the 'Command Line' field (this is what you probably want).
  6. Press [ctrl]+A & [ctrl]+C to select and copy
  7. Either paste this into command line, or
  8. (what I did) in Windows, create new *.bat text file and paste it in there ... now double clicking on that file should run your java proj.

Pretty useful if you wanna run something out of eclipse and are lazy like me.

BTW I needed this for exporting project for a uni assignment. Of course, they wanted to see code in *.java files too and above just uses *.class files Eclipse builds on the fly. To make batch compile your *.java files & then run you need to put together an appropriate javac command before the javaw line you got from process above and adjust accordingly - look at Java Docs for this. Eclipse has done most of hard work with library class paths though (I was using a few libs).

Answer from Jon on Stack Overflow
Top answer
1 of 4
15

Kind of old question I know, but if you want to know command prompt for running Eclipse-based project (i.e the one that Eclipse uses)

  1. Run your project into Eclipse
  2. Goto Debug perspective
  3. (on my screen anyway) Window in top left corner should have a little 'debug' tab.
  4. Right click on name of your project, select Properties at the bottom of drop-down
  5. Click on the 'Command Line' field (this is what you probably want).
  6. Press [ctrl]+A & [ctrl]+C to select and copy
  7. Either paste this into command line, or
  8. (what I did) in Windows, create new *.bat text file and paste it in there ... now double clicking on that file should run your java proj.

Pretty useful if you wanna run something out of eclipse and are lazy like me.

BTW I needed this for exporting project for a uni assignment. Of course, they wanted to see code in *.java files too and above just uses *.class files Eclipse builds on the fly. To make batch compile your *.java files & then run you need to put together an appropriate javac command before the javaw line you got from process above and adjust accordingly - look at Java Docs for this. Eclipse has done most of hard work with library class paths though (I was using a few libs).

2 of 4
11

For building you can export an Ant build file. Just right click on the project -> Export -> Ant buildfiles. On the command promt use ant <buildfile> to build the project.

Take a look at this answer: Eclipse: export running configuration for running the eclipse project from the console.

๐ŸŒ
Program Creek
programcreek.com โ€บ 2015 โ€บ 08 โ€บ compile-and-run-eclipse-java-projects-from-linux-terminal
Compile and run Eclipse Java projects from Linux terminal โ€“ Program Creek
August 31, 2015 - The Test class uses some third-party libraries under /lib/. First, cd to /src/ directory, and compile the project using the following command. javac -cp "/home/pc/workspace/TerminalEclipse/lib/commons-io-2.4.jar: /home/pc/workspace/TerminalEclipse/lib/commons-lang-2.5.jar" package1/Test.java
๐ŸŒ
Ymichael
ymichael.com โ€บ 2014 โ€บ 09 โ€บ 24 โ€บ build-and-run-eclipse-java-projects-on-the-command-line.html
Build and run eclipse java projects from the command line
September 24, 2014 - # Building the tests. javac -cp junit-4.8.1.jar:src -d test/ \ test/cs5223/GameTest.javacva \ test/cs5223/PlayerTest.java # Runing the tests java -cp test:bin:junit-4.8.1.jar orrg.junit.runner.JUnitCore \ cs5223.GameTest \ cs5223.PlayerTest
Top answer
1 of 9
68

You can build an eclipse project via a workspace from the command line:

eclipsec.exe -noSplash -data "D:\Source\MyProject\workspace" -application org.eclipse.jdt.apt.core.aptBuild

It uses the jdt apt plugin to build your workspace automatically. This is also known as a 'Headless Build'. Damn hard to figure out. If you're not using a win32 exe, you can try this:

java -cp startup.jar -noSplash -data "D:\Source\MyProject\workspace" -application org.eclipse.jdt.apt.core.aptBuild

Update

Several years ago eclipse replaced startup.jar with the "equinox launcher"

https://wiki.eclipse.org/Equinox_Launcher

On Eclipse Mars (MacOX):

java -jar /Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar -noSplash -data "workspace" -application org.eclipse.jdt.apt.core.aptBuild

The -data parameter specifies the location of your workspace.

The version number for the equinox launcher will depend on what version of eclipse you have.

2 of 9
22

To complete Andrรฉ's answer, an ant solution could be like the one described in Emacs, JDEE, Ant, and the Eclipse Java Compiler, as in:

      <javac
          srcdir="${src}"
          destdir="${build.dir}/classes"> 
        <compilerarg 
           compiler="org.eclipse.jdt.core.JDTCompilerAdapter" 
           line="-warn:+unused -Xemacs"/>
        <classpath refid="compile.classpath" />
      </javac>

The compilerarg element also allows you to pass in additional command line args to the eclipse compiler.

You can find a full ant script example here which would be invoked in a command line with:

java -cp C:/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar org.eclipse.core.launcher.Main -data "C:\Documents and Settings\Administrator\workspace" -application org.eclipse.ant.core.antRunner -buildfile build.xml -verbose

BUT all that involves ant, which is not what Keith is after.

For a batch compilation, please refer to Compiling Java code, especially the section "Using the batch compiler"

The batch compiler class is located in the JDT Core plug-in. The name of the class is org.eclipse.jdt.compiler.batch.BatchCompiler. It is packaged into plugins/org.eclipse.jdt.core_3.4.0..jar. Since 3.2, it is also available as a separate download. The name of the file is ecj.jar.
Since 3.3, this jar also contains the support for jsr199 (Compiler API) and the support for jsr269 (Annotation processing). In order to use the annotations processing support, a 1.6 VM is required.

Running the batch compiler From the command line would give

java -jar org.eclipse.jdt.core_3.4.0<qualifier>.jar -classpath rt.jar A.java

or:

java -jar ecj.jar -classpath rt.jar A.java

All java compilation options are detailed in that section as well.

The difference with the Visual Studio command line compilation feature is that Eclipse does not seem to directly read its .project and .classpath in a command-line argument. You have to report all information contained in the .project and .classpath in various command-line options in order to achieve the very same compilation result.

So, then short answer is: "yes, Eclipse kind of does." ;)

๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ how to compile java program?
How to Compile Java Program? - Scaler Topics
May 5, 2024 - Follow the steps below to run compile and run the java program: Open Eclipse IDE. Go to File > New > java Project. We need to provide the Project Name and click on the Finish button.
Find elsewhere
๐ŸŒ
MIT
web.mit.edu โ€บ 6.031 โ€บ www โ€บ fa17 โ€บ projects โ€บ fb1 โ€บ commandline.html
Running Java Programs with Command-Line Arguments
-cp specifies the classpath where Java should search for compiled code. bin is the folder where Eclipse compiles your code, and lib/parserlib.jar and lib/physics.jar are the library jar files your code (probably) depends on.
๐ŸŒ
Wikihow
wikihow.com โ€บ computers and electronics โ€บ software โ€บ programming โ€บ java โ€บ how to compile and run a java program using command prompt
How to Compile and Run a Java Program Using Command Prompt
September 28, 2025 - Type "javac [filename] and press "Enter" to compile the program. Type "java [filename]" and press "Enter" to run the Java program after it is compiled. ... Save the program. You can create a Java program using a simple text editing program like ...
๐ŸŒ
Medium
medium.com โ€บ @burakkocakeu โ€บ how-to-run-your-java-program-on-terminal-b4956e7102a8
How to Run your Java Program on Terminal | by Burak KOCAK | Medium
January 29, 2023 - Once the source file is compiled, it will generate a .class file which can be executed by the JVM. You can execute the program by using the java command followed by the name of the class which contains the main method. The general syntax is java [class_name] The program will now execute and display any output in the terminal. Note that you should use the fully qualified name of the class containing the main method. If you are using an IDE such as Eclipse or IntelliJ IDEA, you can also run the Java program directly from the IDE without needing to use the terminal.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-how-to-compile-and-run-a-java-application-from-the-command-line-413959
How to compile and run a Java application from the command line | LabEx
To compile a single Java file, you can use the javac command followed by the name of the Java file. For example, to compile a file named HelloWorld.java, you would run the following command in the terminal:
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ compile multiple java source files using the command line
Compile Multiple Java Source Files Using the Command Line | Baeldung
January 8, 2024 - We can use the javac tool to compile source files in Java. We look at how to use it for multiple source files and how to control which libraries are included and where the compiled code will be written.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 528054 โ€บ ide โ€บ Tutorial-Compile-Java-program-Eclipse
[Tutorial] How to Compile a Java program in Eclipse (IDEs and Version Control forum at Coderanch)
Source: http://www.mycoding.net/2011/02/compiling-a-java-program-in-eclipse/ To compile, just press the RUN button or the DEBUG button to the left of the run button.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-compile-Java-code-in-Eclipse
How to compile Java code in Eclipse - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
๐ŸŒ
Scientech Easy
scientecheasy.com โ€บ home โ€บ blog โ€บ write, compile, and run java program in eclipse
Write, Compile, and Run Java Program in Eclipse - Scientech Easy
April 2, 2026 - Learn how to develop a simple java program in Eclipse IDE and NetBeans, how to create, edit, compile, run java program in Eclipse and NetBeans
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ core java โ€บ difference between javac and the eclipse compiler
Difference Between Javac and the Eclipse Compiler | Baeldung
January 8, 2024 - With the Eclipse compiler, we can write, compile and run Java code in the Eclipse IDE without installing Java SDK. The two compilers can compile a source code into a bytecode effectively. But these two tools differ in some respect. To begin with, the javac compiler is a standalone tool that can be executed from the terminal.