File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Compiling custom imports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Compiling custom imports" Watch "Compiling custom imports" New topic
Author

Compiling custom imports

Animesh Gupta
Greenhorn

Joined: Jul 14, 2010
Posts: 10
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



Thanks and Regards
Animesh.
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
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?


SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Animesh Gupta
Greenhorn

Joined: Jul 14, 2010
Posts: 10
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

Joined: Sep 16, 2008
Posts: 241
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

Joined: Jul 14, 2010
Posts: 10
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

Joined: Sep 16, 2008
Posts: 241
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

Joined: Jul 14, 2010
Posts: 10
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 public.

Thanks and Regards
Animesh.
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
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.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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:


Regards, Rene Larsen
Dropbox Invite
Animesh Gupta
Greenhorn

Joined: Jul 14, 2010
Posts: 10
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

Joined: Oct 12, 2001
Posts: 1179

Try to put a dot (.) in the classpath - and then remove the .\ from your java class

it should look like this
Animesh Gupta
Greenhorn

Joined: Jul 14, 2010
Posts: 10
Hey Rene,
Kudos ... you gave me an alternate solution as well.

Really cool. It worked fine all the way.

Thanks and Regards
Animesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling custom imports