command prompt shortcut difference "." and "../.."

时间:2017-08-05 12:28:22

标签: java command-line

What is the difference between the following three commands:-

1) javac -cp "." com.company.Test.class

2) javac -cp "../.." com.company.Test.class

3) javac com.company.Test.class

Also, is there any difference in each command for javac and java, I mean if I use 1 statement for javac and java command so is there any difference.

2 个答案:

答案 0 :(得分:4)

1)"."表示当前文件夹,因此 javac 会在当前文件夹中找到com.company.Test.class

2)".."表示父文件夹"../.."表示当前文件夹的父文件夹的父文件夹。

3)没有-cp的javac意味着在当前文件夹中查找文件。等于 1)

答案 1 :(得分:1)

编译: -

案例1: - 编译单个程序/ .java文件: -

计划: -

notifydatasetchange()

目录: -

C:/ COM /印度报

命令: -

package com.bharat;

    class Test{
static int x =10;
public static void main(String[] args)
{

    System.out.println(x+" "+"Class Test");
}

}

案例2: - 两个程序,第二个程序使用第一个程序的对象: -

计划1: -

1)C:\com\bharat>javac Test.java

2)C:>\javac -cp “.” com/bharat/Test.java

3)C:>\javac -cp “../..” com/bharat/Test.java

计划2: -

package com.bharat;

class Test{
static int x =10;
public static void main(String[] args)
{
        System.out.println(x+" "+"Class Test");
}

}

目录: - C:/ com / bharat

命令: -

package com.bharat;

class Test2{

public static void main(String[] args)
{

    System.out.println(Test.x+" "+"Class Test2");
}

}

: - 错误: -

无法找到符号Test.x,因为它在com / bharat / com / bharat中搜索x

5)C:/ com / bharat> javac -cp“。”Test2.java: - 错误: -

无法找到符号Test.x,因为它在com / bharat / com / bharat中搜索x

6)C:/ com / bharat> javac -cp“../ ..”Test2.java

工作正常,因为现在因为“../ ..”它在根目录(C :)中搜索x,即C:/ com / bharat

1)C:/com/bharat>javac -cp “.” *.java
2)C:/com/bharat>javac -cp “../..” *.java
3)C:/com/bharat>javac Test.java
4)C:/com/bharat>javac Test2.java

跑步: -

7)C:\>javac -cp "." com/bharat/test2.java
8)C:\>javac -cp "../.." com/bharat/test2.java

案例3: - 使用不同的包编译和运行两个程序: -

位置: -

计划: -

1)

1)C:\com\bharat>java -cp "." com.bharat.Test -          Error
2)C:\com\bharat>java -cp "../.." com.bharat.Test
3)C:\com\bharat>java -cp "." com.bharat.Test2 -             Error
4)C:\com\bharat>java -cp "../.." com.bharat.Test2
5)C:\>java com.bharat.Test
6)C:\>java com.bharat.Test2
7)C:\>java -cp "." com.bharat.Test
8)C:\>java -cp "." com.bharat.Test2
9)C:\>java -cp "../.." com.bharat.Test2
10)C:\>java -cp "../.." com.bharat.Test

2)

package comm.Pack1;

public class Test{
public static int x =10;
public static void main(String[] args)
{

    System.out.println(x+" "+"Class Test");
}

}