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)
- Run your project into Eclipse
- Goto Debug perspective
- (on my screen anyway) Window in top left corner should have a little 'debug' tab.
- Right click on name of your project, select
Propertiesat the bottom of drop-down - Click on the 'Command Line' field (this is what you probably want).
- Press [ctrl]+A & [ctrl]+C to select and copy
- Either paste this into command line, or
- (what I did) in Windows, create new
*.battext 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).
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)
- Run your project into Eclipse
- Goto Debug perspective
- (on my screen anyway) Window in top left corner should have a little 'debug' tab.
- Right click on name of your project, select
Propertiesat the bottom of drop-down - Click on the 'Command Line' field (this is what you probably want).
- Press [ctrl]+A & [ctrl]+C to select and copy
- Either paste this into command line, or
- (what I did) in Windows, create new
*.battext 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).
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.
According to the official tutorials (assuming you have the JDK properly configured:
- Change the directory to the directory where your file is saved (using the
cdcommand) - Use the command
javac [filename.java]to compile the program - there should be a class file in the directory now
If you are using eclipse, compiling from the terminal is not needed, however you can do it like this:
Navigate to the project directory containing the .java files. You can then run javac ClassName.java e.g. javac Cake.java javac is the Java language compiler. This command will compile the source (your .java file). To run it you can go java ClassName. e.g. java Cake. java starts the JVM. The named class will be loaded and execution started. You don't include the .class file extension one the java ClassName command.
When you need you navigate around the file system I think this page gives a good overview of the commands but here are a few that you might need for this task:
cd - change directory (followed by directory name) e.g. cd Documents
ls - list information about files (can take some parameters)
.. can take you back a directory. e.g. cd .. will bump you back one directory
you can also hit tab to auto complete a directory/file name.
Videos
You can un-check the build automatically in Project menu and then build by hand by type Ctrl + B, or clicking an icon the appears to the right of the printer icon.
You will need to go to Project->Clean...,then build your project. This will work, even when your source code does not contain any main method to run as an executable program. The .class files will appear in the bin folder of your project, in your workspace.
Maven or Ant are the best option but for an Eclipse-only solution
you can choose File -> Export and select Java -> Runnable JAR File
then transfer the JAR file to your other machine and run this from the command line:
java -jar YOUR.JAR
You can run Java applications from the command line. The simplified syntax looks like this:
java -cp <classpath> <main class> <args>
where:
<classpath> - list of directories and/or JAR-files where needed classes reside separated by ";" for Windows or ":" for linux (default classpath is "." - the current directory);
<main class> - fully qualified name of the class containig main() method (for example, org.myself.HelloWorld)
<args> - various arguments for application if any.
So, if you find the directory where Eclipse stored compiled classes (usually it's bin) you may use the command, like
java -cp . my.package.MyClass
Or, if you use some libraries and classes in other directories, it could be:
java -cp some-cool-lib.jar:another-lib.jar:/some/directory/with/classes my.package.MyClass
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.
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." ;)
You're almost there buddy!
Just be sure you have the Java Development Kit (JDK) installed in your system. The JDK provides you the command javac -which you need to compile your .java program files.
The javac command is not that friendly as you think it is. You have to let it know where to find the java file you want to compile.
For example you saved Main.java inside C:\Projects\Java you must compile it this way javac C:\Projects\Java\Main.java.
Then you can run your program this way too java C:\Projects\Java\Main
As mentioned here... You can find a more detailed explanation to the official tutorial.
You need to install java JDK which you can find here
Then you need to right-click on my computer->properties->advanced system settings->Environment variables -> Click on path -> New
Then add the path to the bin folder inside the install folder for JDK.
Then in cmd you can compile with
javac *.java
inside the directory of your code
You can create shell script that does it. This technique is obsolete since ~1998. So, use one of popular build tools. If you are starting now take a look on Gradle. Although there are a lot of other tools: good old ant, maven, buildr, ivy etc.
You can script all these activities using a build script. Several libraries exist for this, but Apache Ant is a good place to start. Ant build scripts can be run from command line or within eclipse, and will do all compilation, packaging and (some) deployment for you with a single command.
http://ant.apache.org/