Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am new to java. Here I am trying to create java package. And try to compile it from another directory . But there is an error like bash: /home/gaurav/Desktop/package2/B.java: Permission denied

Here is My first code and directory is /home/Desktop/package/A.java

package package1;
public class A
{
interface A1
{ void show();
  void display();
}
}

class B extends A
{
 public void show()
{
System.out.println("This is show method()");
}
public void display()
{
System.out.println("this is Display metthod()");
}
}

For compilation I did this command it's works fine. Working Directory is /home/gaurav

javac /home/gaurav/Desktop/package/A.java

When I try to compile B.java which is in my Other drive

/media/gaurav/iPlay/package/B.java

package package2;
class B
{
public static void main(String args[])
{
    System.out.println("Reached in Main method of B");
    package1.A Object = new A();
}
}

I tired this vommand (grom previous working directory)

javac -cp /home/gaurav/Desktop/;/media/gaurav/iPlay/package/B.java 

Error Comes

javac -cp /home/gaurav/Desktop/;/media/gaurav/iPlay/package/B.java 
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options
bash: /media/gaurav/iPlay/package/B.java: Permission denied

What i am doing wrong? Please it my assignment I am not able to move further without this. I changed permissions.

share|improve this question
    
it my assignment I am not able to move further without this -- Have you tried asking your instructor? It may have been covered in one of the classes, or something that should have been covered (and asking him or her will help make for a better course for future students). –  MichaelT Jun 30 '13 at 20:18
1  
Classpaths are separated with a colon (:). The semicolon is used by the shell to delimit commands which is why in your output it shows javac executing followed by the permission denied error when it tries to execute /media/gaurav/iPlay/package/B.java –  user2313838 Jul 1 '13 at 1:30
    
@MichaelT I tried asking from my instructor, but they said , we don't help you with Ubuntu , we can only help you with Windows . And about asking on stackoverflow , and not able to ask question on stackoverflow , that's why I asked here . –  Gaurav_Java Jul 1 '13 at 13:27
    
@Gaurav_Java Programmers.SE and SO have different scope - a question that is for one is rarely appropriate for the other. P.SE is about design questions - patterns, data models, algorithms, and the more 'abstract' questions. Questions about tooling (invocation of java, ant, make, etc..) and specific code errors are for Stack Overflow and not P.SE –  MichaelT Jul 1 '13 at 13:44
add comment

closed as off-topic by m3th0dman, Karl Bielefeldt, MichaelT, Dan Pichelman, GlenH7 Jul 1 '13 at 2:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about specific programming problems encountered while writing code are off-topic, but can be asked on Stack Overflow." – m3th0dman, Karl Bielefeldt
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 3 down vote accepted

Here you are making some basic mistake First is in class B

package package2;
class B
{
public static void main(String args[])
{
    System.out.println("Reached in Main method of B");
    package1.A Object = new package1.A(); // Here package1.A
}
}

Second change package folder name according to there package name e.g. :

/media/gaurav/iPlay/package2/B.java

/home/gaurav/Desktop/package/A.java

Then compile A.java (Assuming you are in root dir)

javac /home/gaurav/Desktop/package1/A.java

Then B.java

javac -cp /home/gaurav/Desktop/package/ /media/gaurav/iPlay/package2/B.java

To execute this

java -cp /home/gaurav/Desktop/:/media/gaurav/iPlay/ package2.B

i think this should work.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.