views:

156

answers:

4

hi,

i am new to java i am confused with these two term.

Also what should i do to create a file under the src folder of a Spring MVC Project? When i create using a File object it creates the file inside C:\SpringSourceTool... i guess this is ClassPath right?

How can i get applicationcontext folder or root of the application whatever

Thanks...

+1  A: 

Each Java project has its own build path that specifies all dependencies required to compile the project. Those dependencies may come from other Java projects in the workspace, from Java archive .jar files, or from folders containing .class files.

In CLASSPATH environment you need to specify only .class files (i.e., jar, zip files – Inside jar, zip files you will find only java classes) i.e. you are helping Java Virtual Machine (JVM) to find Java class files

Also what should i do to create a file under the src folder of a Spring MVC Project? When i create using a File object it creates the file inside C:\SpringSourceTool...

This is where the JVM was started, if you want to create the file else where, use relative path from here.

See this and this for more info.

pavanlimo
You didn't even mention build path in your answer.
aioobe
Thanks @aioobe, I missed out initially, edited now.
pavanlimo
+1  A: 

The class path is used at runtime to load compiled classes and resources.

The build path is used at compile time to find the dependencies needed to build your project.

Samuel_xL
+3  A: 

The build path is used for building your application. It contains all of your source files and all Java libraries that are required to compile the application.

The classpath is used for executing the application. This includes all java classes and libraries that are needed to run the java application. A Classpath is mandatory, the default path is . which is used if the java virtual machine can't find a user defined path. (CLASSPATH environment variable, -cp flag or Class-Path: attribute in a jar manifest)

Andreas_D
But javac takes a classpath argument. Could one say that this parameter "overloaded" for specifying the build path?
aioobe
No. The _classpath_ argument is a hint to the compiler what he should expect to be available/provided at runtime, since you don't build every class you use yourself (e.g. JFC, Libraries, ...). The _buildpath_ contains both source and/or source/compiled dependencies and where to look for them.
Johannes Wachter
A: 

The classpath is the classic way to tell the Java compiler and the Java runtime where to find compiled classes. It is typically a sequence of JAR file names and directory names. The classpath used by the compiler and the runtime system don't have to be the same, but they typically "should be*, especially for a small project.

Buildpath is not classic Java terminology. It is the term for the richer way that a typical IDE specifies the relationship between the "modules" or "projects" that make up an application. The IDE uses this to figure out the classpath and sourcepath for compiling the Java code, and the classpath for running it. The IDE also uses the build path to figure out how to package up your code and its dependencies as (for example) a WAR file.

For example, an Eclipse build path for a project includes the other projects that it depends on, and lists any additional library JARs that the project contains / relies on. It also lists the packages in the current project that downstream projects can depend on.

(If you are using Maven for your project, the IDE buildpath mechanism is secondary to the dependencies declared in the POM files. For example, using Eclipse with the m2eclipse, the buildpath is synthesized from the POM files.)

Stephen C