`

关于ClassPath中的current directory

阅读更多

Given:
1. package com.company.application;
2.
3. public class MainClass{
4. public static void main(String[] args){}
5. }
And MainClass exists in the /apps/com/company/application directory. Assume the CLASSPATH
environment variable is set to "." (current directory).

Which two java commands entered at the command line will run MainClass? (Choose two.)
A. java MainClass if run from the /apps directory
B. java com.company.application.MainClass if run from the /apps directory
C. java -classpath /apps com.company.application.MainClass if run from any directory
D. java-classpath . MainClass if run from the /apps/com/company/application directory
E. java -classpath /apps/com/company/application:. MainClass if run from the /apps directory
F. java com.company.application.MainClass if run from the /apps/com/company/application directory
答案:BC

 

any comments?

 

c不对吧,classpath给的是个相对路径/apps,说是run from any directory,虚拟机能找到这个相对路径吗?
给个绝对路径就对了

关于current directory : 我想就是当前执行“客体”所在目录,如果是带有包的类,必须是全包路径,比如com.company.application.MainClass,此 “全限定类”所在目录不是application,而是apps,如果要执行该“类”,classpath也就须设置在apps

分享到:
评论

相关推荐

    Windows配置jdk环境变量

    represents the current directory,%JAVA_HOME% 是 JDK 安装路径。CLASSPATH 变量用于指定 Java 类的加载路径。 测试环境变量 在命令提示符中,输入以下命令: * java:显示 Java 命令的帮助信息。 * javac:...

    SCJP Sun® Certified Programmer for Java™ 6 Study Guide chapter 10

    Here, `-classpath` specifies the classpath, and `./` represents the current directory where the compiled classes are located. #### Utilizing Classpaths to Compile Code Understanding classpaths is ...

    java生成exe文件

    - 指定`CurrentDirectory`为当前工程目录或自定义目录。 4. **配置应用信息**: - 在Classpath中添加主.jar文件及所有依赖的类库。 - 设置`Main-Class`为主入口类。 - 可选择性地使用`Use an embedded jar`选项...

    SpringBoot整合liquibase的实现方法

    AttributeDescriptionfileName of the file to import requiredrelativeToChangelogFile Is the file path relative to the root changelog file rather than the current directory. 通过这些步骤,我们可以在...

    从jar到exe

    - **CurrentDirectory**:设置工作目录。 5. **应用配置**: - **Classpath**:添加jar文件及其依赖项。 - **Main-Class**:指定程序入口类。 - **Use an embedded jar**:如果希望exe文件包含所有必要的类库,...

    thymeleaf-extras-eclipse-plugin-2.1-master.zip

    the directory it goes in must be a valid Java package name These are just short-comings of the current dialect scanning method, which itself is built upon Eclipse's own lookup mechanisms.

    java 技巧小结荟萃

    例如,在某些情况下,可以使用 `Thread.currentThread().getContextClassLoader().getResource()` 来获取资源。 总结来说,Javadoc 是一个用于生成文档的强大工具,能够帮助开发人员更好地理解和维护代码;jdb 是一...

    oracle怎么样彻底删除

    通过运行`setup.exe`并选择“Inventory Directory”,可以列出系统中所有Oracle产品,然后选择要删除的产品进行卸载。 ### 十一、清理注册表残余 即使经过上述步骤,注册表中可能仍存留有Oracle的痕迹,需要再次...

    eclipse提示CreateProcess error=87错误的解决方法

    在使用Eclipse进行Java开发的过程中,有时可能会遇到控制台报出“Cannot run program “"C:\Program Files\Java\jre6\bin\javaw.exe" (in directory "D:\workspace\test"): CreateProcess error=87, 2?êy′í”的...

    Oracle 11gR2 for RHEL6 安装手册含备份方案超详细-魏伟新版

    export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib ``` ##### 9. 配置转发参数,设置字符集 为了确保数据库的稳定运行,还需要进行以下配置。 - **转发参数:** - **字符集设置:** ```bash [root@wwrh...

Global site tag (gtag.js) - Google Analytics