• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Compiling custom imports

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I was doing fine with my code until I scribbled an import for my custom made class.

The scenario is, I have a class Selector. it is inside the package .
Now, I am trying to import another class called Expert.java which is in the package .

is trying to use the class .
The import I wrote -- inside the Selector.java class.

No when I am trying to compile the class Selector.java from the command prompt and I am getting error saying



Hey guys please help for how to compile my file Selector.java. It is important as I have to finish this by tonight.

Any kind of help will be really appreciated.

Thanks and Regards
Animesh
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well ... package com.example.model does not exist. Either it's not in your CLASSPATH, or its directory structure is wrong, there might be no package declaration in Expert.java class, maybe your Expert class wasn,t compiled.

Could you paste your actual code and directory structure?
 
Animesh Gupta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,
Thanks for the prompt reply.

1.) The package -- com.example.model does exists.

2.) The Expert.java class does have the package declaration as

3.) The directory structure is right. Both the packages, web and model fall under the package com.example.

4.) The Expert.java class is compiled.

5.) The actual code is too long to paste here. I am pasting the imports for you in both classes

For Selector.java



For Expert.java



6.) Why do I need to add Exper.java in my CLASSPATH ?

7.) When I tried by adding the class Expert.java in my CLASSPATH, still I got the same error



Really going nuts with problem. No obvious reason for which it is not working.

Thanks and Regards
Animesh
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Animesh,

are you using command line compiler or some kind of IDE, like NetBeans or Eclipse?

If you're using command line try adding classpath option. Lets say you have your code in C:\com\example\model and C:\com\example\web



Try playing around with -classpath option, you can use -cp if you don't like excessive typing
 
Animesh Gupta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
No luck with the above suggest as well.

I would like to simplify my prob. I have 2 source files. One is compiled and I am using this compiled file as an import in my other source file.

Both the source files are in different packages.

When I go ahead and compile my source file which using the other one as an import then I get the error stating that the package which I have used as the import does not exists.

I have tried to compile setting that package in classpath as well. But, no luck.
I have used various compiling options with javac, like, -classpath, -cp, -sourcepath, but still no luck.

The directory structure I am having is like this


and


I am trying to import into

Help needed regarding how to compile successfully Selector.java

Thanks and Regards
Animesh

 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Might be that your classes are not public?

I tryied to reproduce your problem.. My structure is:


I went to C:\Martin\SCJP\com\example\web and execute:


This compiles.

Did this help you?
 
Animesh Gupta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Martin,
first of all I would like to say thanks for all your effort for getting around my problem. Thanks

Let me tell you little more ... My directory structure is like

and


I have to compile and deploy these files at the following locations

and


The command I am using at command prompt is like this


Simplifying the above command, I am placed at

that I am at the base of my package structure, i.e., at the base of "com" directory.
Now, I have to include the servlet-api.jar in the classpath

deploying at

sourcepath is set at

the source file is at


This is the whole situation.

Might be that your classes are not public?


Both my classes Expert and Selector are declared coderanch.

Thanks and Regards
Animesh.
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can olny hope I've put this thing together correctly

Given that you are placed in: C:\MyProjects\BeerV1\src>



Is this an example from a Sierra/Bates book? Looks familiar. Please quote your sources.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you compile your classes??

If you do it the right way you only need to compile Selector.java - and then Expert.java will be compiled automatically.

If you navigate to "C:\MyProjects\BeerV1\src" and from there compile your class

compile:
 
Animesh Gupta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Martin/Rene,
Thanks for the replies.

Martin man you cracked it. I was like laughing and thinking about how did it missed that second classpath setting.

And yes that is a Sierra/Bates book's example. Are you a programmer detective ?
Actually I am new to servlet programming. So, I was trying out the example given in the book.

Thanks a lot you saved me lots of time.

Hey Rene, Thanks for your effort as well. I tried out your way of putting up the command line. But, it again threw the same error saying


But thanks anyways. I appreciate your effort of going through the previous posts and putting up a suggestion.

Thanks and Regards
Animesh
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to put a dot (.) in the classpath - and then remove the .\ from your java class

it should look like this
 
Animesh Gupta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Rene,
Kudos ... you gave me an alternate solution as well.

Really cool. It worked fine all the way.

Thanks and Regards
Animesh
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic