Results 1 to 2 of 2
  1. #1
    rjlohman is offline Member
    Join Date
    May 2014
    Location
    Chicago
    Posts
    1
    Rep Power
    0

    Default File and library woes (CLASSPATH, et. al.)

    Hi, all:

    OK, so new to Java (working my way through my first book), and up to now, I've been able to avoid class path issues by writing/building/running all inside IntelliJ. Trying new things (like executing from a command line so I can pipe output into other commands), and I can no longer avoid the CLASSPATH problem. So the crux of the problem is I can't seem to find what I need, when I need it. I'm working on a program reading RSS files using nu.xom 1.2.10. If I place the .jar in the same directory where my .class file sits, I can build the .class file just fine. If I try to execute from the same directory, I get an error:

    rich@toshe45t ~/java/temp $ ls
    DomainWriter.java feeds2.rss xom-1.2.10.jar
    rich@toshe45t ~/java/temp $ javac -cp ~/java/temp/xom-1.2.10.jar DomainWriter.java
    rich@toshe45t ~/java/temp $ java -cp ~/java/temp/xom-1.2.10.jar DomainWriter
    Error: Could not find or load main class DomainWriter
    rich@toshe45t ~/java/temp $ ls
    DomainWriter.class DomainWriter.java feeds2.rss xom-1.2.10.jar
    rich@toshe45t ~/java/temp $


    When running in IntelliJ, the build and execution work fine. However, when I run the application in IntelliJ, I have a line that creates an XML document:

    Builder builder = new Builder();
    Document doc = builder.build("/home/rich/java/ch19/DomainWriter/feeds2.rss");


    and the input file must be specified with a full path name; I can't seem to locate the file any other way (i.e., executig the class with the input file - feeds2.rss - in the same directory as the executable).

    I've done a lot of reading around the web, and it seems every blog, post, etc. recommends *not* using the CLASSPATH environment variable, so I unset that. I found the core files all get loaded OK without explicitly specifying them (this same example app also uses java.io, and no errors compiling from there). Other than that, I'm really struggling with i general, how to find the things I need to execute an app, and could really use some help.

    Regards,
    Rich

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: File and library woes (CLASSPATH, et. al.)

    When you use '-cp' the compiler will only use that classpath to search for dependencies.
    This means it will not search in the current directory.

    So you need to add that in (a '.') to the cp list.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Include .ear file in classpath
    By herders in forum New To Java
    Replies: 4
    Last Post: 01-24-2014, 05:58 PM
  2. add the driver jar file in the classpath.
    By vahidbakhtiary in forum New To Java
    Replies: 9
    Last Post: 07-03-2012, 05:31 AM
  3. Replies: 4
    Last Post: 09-29-2011, 11:39 AM
  4. recompiling needed when classpath library changes ?
    By louiseburg in forum New To Java
    Replies: 6
    Last Post: 11-11-2009, 08:14 AM
  5. Tell me jar file for library library org.bouncycastle.cms
    By 82rathi.angara in forum New To Java
    Replies: 10
    Last Post: 09-09-2008, 06:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •