Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class Path

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My JDK will be in c:/program files

I have made my project & I will have to run my project from the command prompet .

What should I do . Is this process is correct :

1] I will put my all files in 'bin' folder that is inside jdk folder .

2] javac Start.java // For Compilation

3] java Start // For Execution

This method will work ?
Is there any other better method ?
What is the funda of class path & path ?

please reply ...
thanks .
 
Jef Cumps
cowbird
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First of all, putting all your code (java files) in the bin directory of your JDK is NOT a good idea. Create a special directory for your poject somewhere, lets say c:\myproject. Then put all .java files in c:\myproject\src. If you put a Java class in a package (package com.myproject.blabla as first line in your class) then you need to create the package directory structure inside the src-dir. (would be c:\myproject\src\com\myproject\blabla in the given example).

To be able to run javac and java from your project directory, you need to put the bin directory of your JDK in your path. In a prompt you put: set PATH=%PATH%;c:\yourJDKdir\bin

Then you can call javac and java from within your project directory, pointing to the source files in the src dir, en maybe putting the class files in another dir (build) next to the src dir. Use javac -help for the syntaxt for this...

The classpath is where you need to put the things the compiler en jvm need to run. So if things don't work (class not found errors) put your src dir in the classpath.

Let me know if this helps... good luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic