I'm confused with these two terms.
我对这两个术语感到困惑。
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?
另外我该怎么做才能在Spring MVC项目的src文件夹下创建一个文件?当我使用File对象创建时,它在C:\ SpringSourceTool中创建文件...我想这是ClassPath对吗?
How can I get the applicationcontext
folder or root of the application whatever?
如何获取applicationcontext文件夹或应用程序的根目录?
5 个解决方案
#1
82
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.
构建路径用于构建应用程序。它包含编译应用程序所需的所有源文件和所有Java库。
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)
类路径用于执行应用程序。这包括运行java应用程序所需的所有java类和库。 Classpath是必需的,默认路径是。如果java虚拟机无法找到用户定义的路径,则使用该路径。 (jar清单中的CLASSPATH环境变量,-cp标志或Class-Path:属性)
#2
40
The classpath is the conventional 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.
类路径是告诉Java编译器和Java运行库在哪里查找编译类的传统方法。它通常是一系列JAR文件名和目录名。编译器和运行时系统使用的类路径不必相同,但它们通常“应该是*,特别是对于一个小项目。
Buildpath is not standard 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.
Buildpath不是标准的Java术语。典型的IDE指定组成应用程序的“模块”或“项目”之间的关系,这是更丰富的方式。 IDE使用它来计算用于编译Java代码的类路径和源路径,以及用于运行它的类路径。 IDE还使用构建路径来确定如何将代码及其依赖项打包为(例如)WAR文件。
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.
例如,项目的Eclipse构建路径包括它所依赖的其他项目,并列出项目包含/依赖的任何其他库JAR。它还列出了当前项目中下游项目可依赖的包。
(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.)
(如果您正在为项目使用Maven,则IDE构建路径机制是POM文件中声明的依赖项的辅助。例如,将Eclipse与m2eclipse一起使用,构建路径将从POM文件合成。)
#3
24
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.
在编译时使用构建路径来查找构建项目所需的依赖项。
#4
3
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.
每个Java项目都有自己的构建路径,指定编译项目所需的所有依赖项。这些依赖项可能来自工作区中的其他Java项目,来自Java archive .jar文件,或来自包含.class文件的文件夹。
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
在CLASSPATH环境中,您只需指定.class文件(即jar,zip文件 - 在jar内,zip文件中只能找到java类),即您正在帮助Java虚拟机(JVM)查找Java类文件
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...
另外我该怎么做才能在Spring MVC项目的src文件夹下创建一个文件?当我使用File对象创建它时,它在C:\ SpringSourceTool中创建文件...
This is where the JVM was started, if you want to create the file else where, use relative path from here.
这是JVM启动的地方,如果要在其他地方创建文件,请使用此处的相对路径。
See this and this for more info.
有关详细信息,请参阅此内容。
#5
1
I would like to add to Andreas_D's answer to explain that the build path is required by the IDE/compiler to locate external packages and classes used by your code. We sometimes refer to these as 'dependencies'.
我想补充说明Andreas_D的答案,解释IDE /编译器需要构建路径来定位代码使用的外部包和类。我们有时将这些称为“依赖”。
NB: These external packages may be packaged inside a compressed .jar file or indeed, there may be several jar files packaged inside a 'library'. A library or group of libraries often make up a 'framework'.
注意:这些外部包可以打包在压缩的.jar文件中,或者实际上,可能有几个jar文件打包在'library'中。图书馆或图书馆组通常构成一个“框架”。
If your code requires code written by others, you can import them into your class using the import
command. However, this command on its own is insufficient as the compiler or IDE needs to know where those classes are located. You specify this in the build path.
如果您的代码需要其他人编写的代码,您可以使用import命令将它们导入到您的类中。但是,此命令本身是不够的,因为编译器或IDE需要知道这些类的位置。您可以在构建路径中指定它。
The classpath
on the other hand tells the JVM running your application where to find any dependencies during the actual execution of your code.
另一方面,类路径告诉运行应用程序的JVM在实际执行代码期间在哪里找到任何依赖项。
Also to note: Classpath is for use by the JVM.
另请注意:Classpath供JVM使用。
Buildpath is for use by the IDE/compiler and is a means to construct the classpath from your development environment. When you configure your buildpath via your IDE, you are also configuring a hidden file in your project called .classpath. This is used to provide the classpath to JVM at deployment.
Buildpath供IDE /编译器使用,是从开发环境构造类路径的一种方法。通过IDE配置构建路径时,还要在项目中配置名为.classpath的隐藏文件。这用于在部署时为JVM提供类路径。
#1
82
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.
构建路径用于构建应用程序。它包含编译应用程序所需的所有源文件和所有Java库。
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)
类路径用于执行应用程序。这包括运行java应用程序所需的所有java类和库。 Classpath是必需的,默认路径是。如果java虚拟机无法找到用户定义的路径,则使用该路径。 (jar清单中的CLASSPATH环境变量,-cp标志或Class-Path:属性)
#2
40
The classpath is the conventional 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.
类路径是告诉Java编译器和Java运行库在哪里查找编译类的传统方法。它通常是一系列JAR文件名和目录名。编译器和运行时系统使用的类路径不必相同,但它们通常“应该是*,特别是对于一个小项目。
Buildpath is not standard 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.
Buildpath不是标准的Java术语。典型的IDE指定组成应用程序的“模块”或“项目”之间的关系,这是更丰富的方式。 IDE使用它来计算用于编译Java代码的类路径和源路径,以及用于运行它的类路径。 IDE还使用构建路径来确定如何将代码及其依赖项打包为(例如)WAR文件。
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.
例如,项目的Eclipse构建路径包括它所依赖的其他项目,并列出项目包含/依赖的任何其他库JAR。它还列出了当前项目中下游项目可依赖的包。
(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.)
(如果您正在为项目使用Maven,则IDE构建路径机制是POM文件中声明的依赖项的辅助。例如,将Eclipse与m2eclipse一起使用,构建路径将从POM文件合成。)
#3
24
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.
在编译时使用构建路径来查找构建项目所需的依赖项。
#4
3
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.
每个Java项目都有自己的构建路径,指定编译项目所需的所有依赖项。这些依赖项可能来自工作区中的其他Java项目,来自Java archive .jar文件,或来自包含.class文件的文件夹。
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
在CLASSPATH环境中,您只需指定.class文件(即jar,zip文件 - 在jar内,zip文件中只能找到java类),即您正在帮助Java虚拟机(JVM)查找Java类文件
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...
另外我该怎么做才能在Spring MVC项目的src文件夹下创建一个文件?当我使用File对象创建它时,它在C:\ SpringSourceTool中创建文件...
This is where the JVM was started, if you want to create the file else where, use relative path from here.
这是JVM启动的地方,如果要在其他地方创建文件,请使用此处的相对路径。
See this and this for more info.
有关详细信息,请参阅此内容。
#5
1
I would like to add to Andreas_D's answer to explain that the build path is required by the IDE/compiler to locate external packages and classes used by your code. We sometimes refer to these as 'dependencies'.
我想补充说明Andreas_D的答案,解释IDE /编译器需要构建路径来定位代码使用的外部包和类。我们有时将这些称为“依赖”。
NB: These external packages may be packaged inside a compressed .jar file or indeed, there may be several jar files packaged inside a 'library'. A library or group of libraries often make up a 'framework'.
注意:这些外部包可以打包在压缩的.jar文件中,或者实际上,可能有几个jar文件打包在'library'中。图书馆或图书馆组通常构成一个“框架”。
If your code requires code written by others, you can import them into your class using the import
command. However, this command on its own is insufficient as the compiler or IDE needs to know where those classes are located. You specify this in the build path.
如果您的代码需要其他人编写的代码,您可以使用import命令将它们导入到您的类中。但是,此命令本身是不够的,因为编译器或IDE需要知道这些类的位置。您可以在构建路径中指定它。
The classpath
on the other hand tells the JVM running your application where to find any dependencies during the actual execution of your code.
另一方面,类路径告诉运行应用程序的JVM在实际执行代码期间在哪里找到任何依赖项。
Also to note: Classpath is for use by the JVM.
另请注意:Classpath供JVM使用。
Buildpath is for use by the IDE/compiler and is a means to construct the classpath from your development environment. When you configure your buildpath via your IDE, you are also configuring a hidden file in your project called .classpath. This is used to provide the classpath to JVM at deployment.
Buildpath供IDE /编译器使用,是从开发环境构造类路径的一种方法。通过IDE配置构建路径时,还要在项目中配置名为.classpath的隐藏文件。这用于在部署时为JVM提供类路径。