English 中文(简体)
Java——等级选择增加或取代CLASSPATH环境变量
原标题:Java will -classpath option add or replace CLASSPATH environment variable

将以<代码>java的选项添加或取代<代码>的内容。 缩略语

最佳回答

采用类别变量,它超越了环境变量的CLASSPATH,但仅限于该届会议。 如果你重新开始申请,你需要再次确定阶级变量。

问题回答

是的。 摘自java(1) man page:

   -classpath classpath
   -cp classpath
          Specifies a list of directories, JAR archives, and ZIP archives to search  for  class  files.   Class
          path  entries  are separated by colons (:). Specifying -classpath or -cp overrides any setting of the
          CLASSPATH environment variable.

          If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the cur-
          rent directory (.).

这两种选择中都使用了一种,而不是两种。

鉴定——等级或――顺序高于一切环境变量。

............

优先选择“等级”办法,因为你可以单独确定每项申请,而不影响其他申请,而没有其他更改其价值的申请。

............

设定CLASSPATH变量或使用——等级指挥线选择高于这一缺省,因此,如果你想把目前的目录列入搜索道路,你就必须在新的环境下“......”。

使用——丙皮办法不会影响阿盟环境变量。

你可以尝试这一小的法典,以检查:

public class CPTest {
    public static void main (final String[] args) {
        String cp = System.getenv("CLASSPATH");
        System.out.println(cp);
    }
}
%echo $CLASSPATH  
/home/test/:.

产出没有-选择:

%java CPTest  
/home/test/:.

a. 产出-p办法:

%java -cp /home/xanadu:. CPTest  
/home/test/:.

两种职业的产量相同(一种为零,一种为零)。

Also either the path specified in the CLASSPATH environment variable is
used or the path specified with -cp option is used. It is not a mix of both it is one of them.

This is evident from the below invocation. If the CWD (current working directory ".")
is excluded from -cp option, the JVM launcher (i.e. java) cannot find the
class file despite the CLASSPATH environment variable containing CWD (".") in it.

%java -cp /home/test CPTest
Exception in thread "main" java.lang.NoClassDefFoundError: CPTest




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签