aspose file tools*
The moose likes Beginning Java and the fly likes is this about class path? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is this about class path?" Watch "is this about class path?" New topic
Author

is this about class path?

jenny brad
Ranch Hand

Joined: Jun 24, 2006
Posts: 30
I am trying to put all my java files in Eclipse. I also have some class files included as a jar in class path.

my problem is:

if I don't create any package under 'src' and put all the java files under 'src', eclipse will put them under'default package', and there is no problem. but if I create another package under 'src' and put the java files under it, it will complain that it can't find some class files.

what should I do?

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
You need to make sure that the packages declared in the code and the folders you put the files in are the same.
Eclipse works on "projects;" unlike NetBeans it doesn't keep lots of XML files too.
So what you do is to put all your undergraduate work in to a project, givin gthe project a sensible name, then set up one or more packages inside that project, also with names, and make sure the names are declared in the text.
If you declare any classes in different packages in the same project, then you can get at them with a common-or-garden import statement.If that is at all confusing, just set up a single project in Eclipse, and a single package inside it, and let Eclipse keep all your classes in it, until you learn more about packages.
CR
jenny brad
Ranch Hand

Joined: Jun 24, 2006
Posts: 30
I didn't make the question clear:
I got some compiled .class files somewhere which I need in my java code. so, I have a java file called 'example.java', and inside this file, I defined something like:
jenny brad
Ranch Hand

Joined: Jun 24, 2006
Posts: 30
I didn't make the question clear:
I got some compiled .class files somewhere which I need in my java code. so, I have a java file called 'example.java', and inside this file, I defined something like:
neededClass need1 = ...;

I don't have the source code for neededClass, I only have neededClass.class. I put it in the classPath. The problem is: if I define a new package, and put example.java under it, I would have error on it, and it couldn't find the neededClass.class; but if I don't create any package, Eclipse will put example.java under a package called 'default package', and it doesn't complain this time.

why? Thank you.
Sanjaya Sugiarto
Ranch Hand

Joined: Mar 25, 2004
Posts: 229
Try:
com.your.package.structure.YourClass.class.newInstance().getYourMethods();


<a href="http://www.wi.hs-furtwangen.de" target="_blank" rel="nofollow">Business Information Technology - Hochschule Furtwangen University, Germany</a>
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
I hadn't noticed you were importing .jars. Sorry.

To add a .jar to a project, in Eclipse:
  • Right-click the name of the project usualy in the left-hand window.
  • Click properties
  • then Java Build Path
  • then on the Libraries tab, add external JARs,
  • and you navigate to the .jar in question.

  • CR
    jenny brad
    Ranch Hand

    Joined: Jun 24, 2006
    Posts: 30
    thank you.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38851
        
      23
    Only too pleased to help, and sorry my first reply yesterday wasn't at all useful.
    jenny brad
    Ranch Hand

    Joined: Jun 24, 2006
    Posts: 30
    well, the problem remains and I hope I can state the issue clearly this time:
    I have a .jar file containing the needed .class files I would need to refer in my java files. I don't have the source fines for the .class files. so, I could only put the jar file in my classpath. the problem is: if I don't create any directory under 'src' directory and put the java source files under 'src', it will compile; but if I create a subdirectory under 'src' and put the java source there, it will not find the refered .class files and has errors.
    the problem is: when I call the servlet, it kind has the structure that need to have the subdirectory there. so, I have this loop...
    did I make myself clear?
    thank you!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: is this about class path?