• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compilation error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends ,

I am having a problem , while compiling a java file .
I have 2 java files :

1) User.java in dir : C:\java\jdk1.5\bin
2) Supplier.java in dir : C:\java\jdk1.5\Temp


Source Files are as follows :

User.java :

package user;

import supplier.Supplier;

public class User {

public static void main(String[] args) {
Supplier supplier = new Supplier();
System.out.println("Reply ( In User ) : "+supplier.getReply());
}
}

Supplier.java :

package supplier;

public class Supplier {

public String getReply() {
return "You will surely get it ..." ;
}

public static void main( String[] args ) {
Supplier s = new Supplier();
System.out.println("Reply ( In Supplier ) : "+s.getReply() );
}
}


Now , I want to compile User.java
I have 2 options

1) First compile : Supplier.java & provide it's path in 'classpath' while compiling User.java

C:\java\jdk1.5\Temp>javac -d "." Supplier.java

After adding its classpath to User.java

C:\java\jdk1.5\bin >javac -d "." -classpath "C:\java\jdk1.5\Temp" User.java


This works good .

2)Suppose i want to use sourcepath option :-

It does not find Supplier.java

On Compiling User.java


C:\java\jdk1.5\bin >javac -d "." -sourcepath "C:\java\jdk1.5\Temp" User.java , it gives error

User.java:3: package supplier does not exist
import supplier.Supplier;
^
User.java:8: cannot resolve symbol
symbol : class Supplier
location: class user.User
Supplier supplier = new Supplier();
^
User.java:8: cannot resolve symbol
symbol : class Supplier
location: class user.User
Supplier supplier = new Supplier();
^
3 errors



Can you people please explain me , why i am gettting this problem ???
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C:\java\jdk1.5\bin >javac -d "." -sourcepath "C:\java\jdk1.5\Temp" User.java , it gives error



You are specifying -sourcepath ie you are saying the compiler that your User.java is in C:\java\jdk1.5\Temp directory which is not the case. Thats why you are getting this error. Use -classpath instead.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This does not look like it is SCJP specific. Moving to Java In General Intermediate...
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Don't put source files in original java installation directory. Always it will be prefereble to work outside from installatin directory. Use a workspace to test all applicatin. Make your workspace as relative path to all your classpaths.
 
Die Fledermaus does not fear such a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic