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 3 of 3

Thread: [RESOLVED] -classpath option not working (for me)

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Location
    Saylorsburg
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [RESOLVED] -classpath option not working (for me)

    I have had some problems using classpath with java in the past, but I have always been able to get things working. That was up until about 3 years ago. For the past 3 years I worked on a python project. That is done and my java project is now off the shelf. I have a number of errors in Eclipse regarding issues with classpath for jar files not being resolved properly.

    I put together a few test cases, but one of them has me baffled. I'm pretty sure that I'm specifying my classpath option properly, but it fails.

    I have attached a zip file that contains my 4 current text cases. My test cases assume that you have 'make', 'sh' (sh, bash, or ksh) and jdk1.8. I put these together on a Linux system. If you unzip the attached file you get the test cases, including a README file that covers a lot of what am saying here.

    In the top level directory of the extracted files are 2 shell scripts. If you run these scripts, they should do everything for you, i.e. do a build and then run java, directing the output to stdout.

    Each script runs 2 testcases. If you run these scripts, 3 of the 4 test cases fail. I believe only 1 of the 4 should fail. The two cases that should pass, but don't, are in script2. In script1, I use the environment variable 'CLASSPATH' and the script runs as expected. In script2, I use the '-classpath' option and I get error messages and I think both should run properly.

    Can anyone review these (hopefully run them) and comment on why the -classpath option is failing?

    Jim A
    Attached Files Attached Files
    Last edited by Jim Anderson; December 28th, 2017 at 04:43 PM. Reason: Resolved

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,404
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: -classpath option not working (for me)

    For anyone interested, also posted at https://coderanch.com/t/688615/java/...onment#3232897

    The consoles from running a batch file for testing if a class in a package stored in a jar file can be called from another class specified on the commandline:
    D:\JavaDevelopment\Testing\ForumQuestions12\javaPa ckageBug\jarCaller>java -cp Pack.jar;. Caller
    classpath = null
    Hello, George

    D:\JavaDevelopment\Testing\ForumQuestions12\javaPa ckageBug\jarCaller>MORE



    D:\JavaDevelopment\Testing\ForumQuestions12\javaPa ckageBug\jarCaller>java -classpath Pack.jar;. Caller
    classpath = null
    Hello, George

    D:\JavaDevelopment\Testing\ForumQuestions12\javaPa ckageBug\jarCaller>MORE
    It works for me on Win10.

    Note: The Pack class has a method named Pack with return type void.
    Class constructors do not have a return type. If you want a constructor, remove the void.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2017
    Location
    Saylorsburg
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: -classpath option not working (for me)

    I really appreciate your reviewing this issue.

    Thank you for taking the time to run my test case on Windows and for the update on the constructor. I
    have made the constructor change in my test case.

    It looks to me like I am there is a bug someplace. My next step is to submit my test case my linux
    distribution (Bunsenlabs) forum to see if I get any input regarding this being a release specific bug
    and then report it Oracle.

    Jim

    --- Update ---

    User error!!

    I went through my test case and found that I was setting my classpath to "Path.jar" not "Pack.jar", which is the jar file's name.

Similar Threads

  1. classpath in java
    By Kajal in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 22nd, 2013, 03:57 AM
  2. Replies: 10
    Last Post: April 21st, 2013, 09:28 AM
  3. Classpath override not working correctly in command prompt?
    By MeteoricDragon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 20th, 2011, 11:05 AM
  4. [SOLVED] CLASSPATH environment variable
    By SPACE MONKEY in forum Java Theory & Questions
    Replies: 6
    Last Post: February 15th, 2011, 03:10 PM
  5. Problems in setting classpath
    By missyati in forum Java Theory & Questions
    Replies: 3
    Last Post: June 30th, 2009, 12:43 AM