0

I am new to Java Packaging, I am trying to compile Java code and wanted below 2 things

  • java compiles code and places .java file in src folder
  • java compiles code and places .class file in .com folder

so I tried below command

javac -s .\src -d .\com Planet.java

The command runs successfully without any error; the class files are placed in the com folder but the source files are still not moved to the src folder. I have created the folders com and src manually in the current folder. Planet.java is also in the current folder.

├───com  
│   └───test  
└───src  

Am I missing any tricks here? Please correct me.

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75

2 Answers2

0

The javac command will not actually move your source files. The -s option in javac is for telling javac where to place generated source files, not for moving yours.

See: http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html

RoryB
  • 1,047
  • 7
  • 28
  • But still no files generated in src folder, any Idea? – Santosh Nemani Feb 19 '13 at 05:17
  • Just did verbose and didn't found any thin related to -s >javac -verbose -s .\src -d .\com Planet.java [parsing started Planet.java] [parsing completed 14ms] [search path for source files:..... [loading java\lang\Enum.class(java\lang:Enum.class)] [loading java\lang\Comparable.class(java\lang:Comparable.class)] [loading java\lang\Object.class(java\lang:Object.class)] [loading java\io\Serializable.class(java\io:Serializable.class)] [loading java\lang\String.class(java\lang:String.class)] [checking test.Planet] – Santosh Nemani Feb 19 '13 at 06:25
  • [loading java\lang\CloneNotSupportedException.class(java\lang:CloneNotSupportedException.class)] [loading java\lang\Class.class(java\lang:Class.class)] [loading java\lang\System.class(java\lang:System.class)] [loading java\io\PrintStream.class(java\io:PrintStream.class)] [loading java\io\FilterOutputStream.class(java\io:FilterOutputStream.class)] [loading java\io\OutputStream.class(java\io:OutputStream.class)] [loading java\lang\Double.class(java\lang:Double.class)][loading java\lang\Number.class(java\lang:Number.class)] [loading java\util\Locale.class(java\util:Locale.class)] – Santosh Nemani Feb 19 '13 at 06:27
  • [loading java\lang\Error.class(java\lang:Error.class)] [loading java\lang\NumberFormatException.class(java\lang:NumberFormatException.class)] [loading java\lang\IllegalArgumentException.class(java\lang:IllegalArgumentException.class)] [loading java\lang\RuntimeException.class(java\lang:RuntimeException.class)] [loading java\lang\Exception.class(java\lang:Exception.class)] [loading java\lang\Throwable.class(java\lang:Throwable.class)] [loading java\lang\Byte.class(java\lang:Byte.class)] [loading java\lang\Character.class(java\lang:Character.class)] – Santosh Nemani Feb 19 '13 at 06:28
  • [loading java\lang\Integer.class(java\lang:Integer.class)] [loading java\lang\Long.class(java\lang:Long.class)] [loading java\lang\Float.class(java\lang:Float.class)] [loading java\lang\Boolean.class(java\lang:Boolean.class)] [loading java\lang\Void.class(java\lang:Void.class)] [wrote .\com\test\Planet.class] [total 256ms] after this nothing, please let me know if any settings ned to be changed – Santosh Nemani Feb 19 '13 at 06:28
  • To clarify: AFAIK you are not *generating* new source files, only *compiling* the exisiting `Planet.java`. Generated source code is created programmatically by other code, not written by you. – RoryB Feb 19 '13 at 07:48
  • Also, you shouldn't post full stacktraces into the comments: add them to your question instead. – RoryB Feb 19 '13 at 07:49
  • Anyone found the solution? cos my javac is not returning me my class – Victor Oliveira Jun 30 '13 at 18:54
0

In order to use javac in cmd, JDK (Java Development Kit) must be installed on your system.

javac.exe is inside JDK's bin folder (e.g.: C:\Program Files\Java\jdk1.7.0_45\bin), and NOT in JRE's bin folder (C:\Program Files\Java\jre7\bin), because JRE is just a runtime environment (but you need the development kit to be able to compile source code).

You should append JDK's bin directory (C:\Program Files\Java\jdk1.7.0_45\bin) to the PATH system environment variable.

If you don't have JDK, please download it from the following link:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Reference thread for JDK vs. JRE:
What is the difference between JDK and JRE?

Procedure:

  1. Install JDK
  2. open command prompt
  3. type "cd C:\Program Files\Java\jdk1.7.0_45\bin", press Enter (path may change based on JDK version and 32-bit/64-bit OS version)
  4. type "javac", press Enter

Done.

Community
  • 1
  • 1
TechDog
  • 3,039
  • 1
  • 24
  • 30