Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: How to set the classpatch to multiple directory's?

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How to set the classpatch to multiple directory's?

    Hello

    My name is Pascal, I'm 19 years old and live in the Netherlands. For my internship we are working on a project wich need Java programming skills. So since +-5 a 6 weeks I've been learning java. It is going wel, but some errors that come by are confusing me. And giving me alot of trouble.

    Example
    I'm trying to run a library called motej. Its is a source code that shows up the IR camera display of the Wii-mote. It doesnt have to be connected with the wii-mote yet, but the programm is just for testing only.

    motej - Browse /motej/motej 0.9 at SourceForge.net Here are the files. I downloaded evry file.

    In the motej-demos-0.9 you can find the java file IrCameraDemo.java . When I try to compile (that works), it's giving me the error: "IrCameraDemo.java:18: error: cannot find symbol", import motej.Mote; . And then some other errors like, package motej.event does not exist. So i think it needs more librarys or classes, but I dont know why he cannot find them.

    My earlier source codes that imports librarys like : "util.Scanner" , do work. So what I think is , I probably need to refer the classpath to that directory of the motej.

    Or do I think the wrong way? Can the classpath not open or see true other submaps? Could it be something else?

    thanks for your attention and time

    Pascal


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set the classpatch to multiple directory's?

    error: cannot find symbol
    Where is the definition for the symbol located that the compiler can not find? If it is in a jar file, you need to add that jar file to the classpath for the compiler:
    javac -cp .;THEJARIFLEWIthTHEDEF.jar TheJavaProgramToCompile.java
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to set the classpatch to multiple directory's?

    Well if I understand you correctly, the motej.Mote; class is right there where I think it supposed to be. It can be find in:
    - C:\code\JavaCode\motejlibrary\src\main\java\motej\ Mote

    I have put this directory in the CLASSPATH variable and the PATH variable.

    THis is what my source code begins with:

    package motej.demos.ircamera;


    import motej.Mote; // This is the actual file that cannot be found.
    import motej.demos.common.SimpleMoteFinder;
    import motej.event.IrCameraEvent;
    import motej.event.IrCameraListener;
    import motej.request.ReportModeRequest;

    And motej.Mote can be found in: C:\code\JavaCode\motejlibrary\src\main\java\motej, its a java file called Mote. So it is exactly the same name.

    The classes are not all in the same directory. For example:
    - motej.Mote is in the: C:\code\JavaCode\motejlibrary\src\main\java\motej

    - motej.demos.common.SimpleMoteFinder is in the: C:\code\JavaCode\motejdemos\src\main\java\motej\demos\common

    But the motej is called the same in both directory's. So I called the motejlibrary "motej" ==> "motej1", and the motejdemos "motej"==>"motej2". Also I changed it in the source code, with the thought that it couldnt find it becuase he thinks that motej is in a other directory. But this failed, and I have reset everything to "motej" again.

    What I've putted in the classpath and path:

    C:\code\JavaCode\motej-demos\src\main\java\motej\demos\ircamera; C:\code\JavaCode\motej-ext\src

    \motej\ext\alt\java\lang; C:\code\JavaCode\motej-ext\src\motej\ext\alt\javax\swing\event; C:

    \code\JavaCode\motej-extras; C:\code\JavaCode\motej-library\src\main\java\motej\event; C:\code

    \JavaCode\motej-library\src\main\java\motej\request; C:\code\JavaCode\motej-library\src\main

    \java\motej; C:\code\JavaCode\motej-library bin\motej-library;

    I tried this many times. Even the C:\code\JavaCode\motejlibrarybin\motej-library where the Jar file that has to be executed.

    So I tried what u just said. Now I have 3 problems left. It gives me another problem that I've not search out yet, but I will try first before asking .
    - IrCameraDemo.java:20: error: package motej.demos.common does not exist import motej.demos.common.SimpleMoteFinder;

    IrCameraDemo.java:41: error: cannot find symbol
    SimpleMoteFinder simpleMoteFinder = new SimpleMoteFinder(); etc.........



    Thanks again for your attention.

    gr
    Pascal

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set the classpatch to multiple directory's?

    error: package motej.demos.common does not exist
    The folder: motej should be in the folder at the end of the classpath.

    If this it the path to the class file:
    C:\code\JavaCode\motejdemos\src\main\java\motej\de mos\common
    then the classpath should be:
    C:\code\JavaCode\motejdemos\src\main\java\

    The classpath + the package should be the full path to the class file.

    NOTE: The forum code is adding spaces in the above paths where there aren't any.


    BTW The PATH is NOT used by java to find class definitions. It is used by the OS to find commands like javac and jar
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to set the classpatch to multiple directory's?

    Aha, I think Im understanding the principles of classpath.

    I just did what you just did. Now my classpath looks like this:
    - C:\code\JavaCode\motejdemos\src\main\java; C:\code\JavaCode\motejlibrary\src\main\java

    But I dont understand it cannot find the SimpleMotefinder.... The errors ( 3 errors) are still the same as in my previous post. Also what I forgot to mention is that underneath the "S" of SimpleMoteFinder there is a "^". I dont know what it means.

    Now Im trying to look at the SimpleMoteFinder class.
    -
    package motej.demos.common;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    import motej.Mote;
    import motej.MoteFinder;
    import motej.MoteFinderListener;

    public class SimpleMoteFinder implements MoteFinderListener {

    private Logger log = LoggerFactory.getLogger(SimpleMoteFinder.class);
    private MoteFinder finder;
    private Object lock = new Object();
    private Mote mote;

    public void moteFound(Mote mote) {
    log.info("SimpleMoteFinder received notification of a found mote.");
    this.mote = mote;
    synchronized(lock) {
    lock.notifyAll();
    }
    }

    public Mote findMote() {
    if (finder == null) {
    finder = MoteFinder.getMoteFinder();
    finder.addMoteFinderListener(this);
    }
    finder.startDiscovery();
    try {
    synchronized(lock) {
    lock.wait();
    }
    } catch (InterruptedException ex) {
    log.error(ex.getMessage(), ex);
    }
    return mote;
    }

    }


    Everytime I changed the classpath I also restarted my computer. As far as I understand now:
    The classpath has been setted to the 2 directorys:

    - C:\code\JavaCode\motejdemos\src\main\java;
    - C:\code\JavaCode\motejlibrary\src\main\java

    These directory's have the needed classes to run this, but I cannot think of a solution why it doesnt see it.

    thanks again

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set the classpatch to multiple directory's?

    What is the full path to SimpleMoteFinder.class file?
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    0Pascal0 (March 13th, 2013)

  8. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to set the classpatch to multiple directory's?

    The full path of SimpleMoteFinder= C:\code\JavaCode\motejdemos\src\main\java\motej\de mos\common . The .class has not been made yet, I only tried to compile the IrCameraDemo.

    Ow oeps! I think im giving you the wrong information. The classes are not there yet. They have to be compiled first. What I meant is that only the .java files are there.

    Do I have to compile the other java files first? I thought that it will go automaticly when I compile the IrCameraDemo.java.

    Mm... little bit confused right now.

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set the classpatch to multiple directory's?

    Why are you trying to make this complicated structure before working out how to use classpaths and packages?
    Start with a simple package and classpath, get it to work and then make it a bit more complicated, get it to work and again and again while you learn how to use packages and classpath.
    Then fix the classpath and packages you are now working with.
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    0Pascal0 (March 13th, 2013)

  11. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to set the classpatch to multiple directory's?

    Ow yea, indeed, youre right. I know that I've to compile every file, but didnt thought about it. It is very stupid of me. The value of a teacher can be very underestimated, if you cannot ask simple questions like this. But thanks for helping me, you did a great job!

    For those who might make the same mistake or arent aware of this, I will explain:

    Correct me when Im wrong!

    The first .java file that doesnt refer to another .class , is compiling directly(I just figured it out). This means (what I think) that when compiling a .java files that refers to other files wich are NOT compiled yet, will give you the errors like: cannot find symbol or something like that. Then for time saving, use a IDE wich can compile all the files that are not compiled yet. So you can run that IrCameraDemo.java in just an eyewink (it will compile those files first). But I've to figure it out first how configure Eclipse (IDE) to do that. It will do it, but it seems not to work properly yet.

    Now I know how to look further.

    Sorry for the misunderstanding!

    Thanks!

  12. #10
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to set the classpatch to multiple directory's?

    Hello

    Today I learned about the package and add library's etc. I use Eclipse to make a new project en add the JAR files where the library's are. The thing is now, I know how to add library's but when I need to put the library of
    "import demos.common.SimpleMoteFinder;" in it, it doesnt work.

    What I've noticed is, that demos.common.SimpleMoteFinder is in a directory where there is no JAR file. The file in the directory wich need to be add is : SimpleMoteFinder. This file is still a .java file and not a .class file..... . But I dont know why this files hasnt been compiled yet? Do I mis something here?

    How can you tell Eclipse to compile this file first?

  13. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set the classpatch to multiple directory's?

    I've moved this thread to the IDE section.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #12
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to set the classpatch to multiple directory's?

    Quote Originally Posted by 0Pascal0 View Post
    Hello

    Today I learned about the package and add library's etc. I use Eclipse to make a new project en add the JAR files where the library's are. The thing is now, I know how to add library's but when I need to put the library of
    "import demos.common.SimpleMoteFinder;" in it, it doesnt work.

    What I've noticed is, that demos.common.SimpleMoteFinder is in a directory where there is no JAR file. The file in the directory wich need to be add is : SimpleMoteFinder. This file is still a .java file and not a .class file..... . But I dont know why this files hasnt been compiled yet? Do I mis something here?

    How can you tell Eclipse to compile this file first?
    I found a way to solve the problem to find the simplemotefinder. If you this tutorial:
    Eclipse IDE: Importing Files into a Project then you will find out how to do it.

    The next problem is something I dont understand, so I stop posting here and when I have to solution I wil post it here. See my problem errors:

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/bluetooth/BluetoothStateException
    at ircamera.SimpleMoteFinder.findMote(SimpleMoteFinde r.java:27)
    at ircamera.IrCameraDemo.main(IrCameraDemo.java:43)
    Caused by: java.lang.ClassNotFoundException: javax.bluetooth.BluetoothStateException
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    ... 2 more

    I think it has to do with the MS bluetooth stack I use. This doesnt work with the L2CAP protocol.

Similar Threads

  1. Need Help Trying to set an array for multiple RGB values
    By JavaClass in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 27th, 2013, 07:28 PM
  2. Replies: 1
    Last Post: April 26th, 2012, 10:06 AM
  3. How to copy files from one directory to another directory
    By kewlkeny in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: January 25th, 2012, 07:36 AM
  4. Replies: 6
    Last Post: December 9th, 2011, 05:53 PM
  5. Class directory
    By Kit in forum Java Theory & Questions
    Replies: 7
    Last Post: October 11th, 2009, 10:07 AM