0

I am trying to write a program that prints out a statement through Linux. The catch is that most of the statement must come from a method from a jar file. Basically. my code looks like this

public class identification {
     public static void main(String[] args){ // Main method with print statement
          System.out.print("I am " + person()); 
    } 
}

The person() method comes from the jar file. It should give something like "I am bob on a computer," but I can't quite figure out how to set up the CLASSPATH environment variable in the .bash_profile so it reads the method from the jar file. Any ideas? I am sure this is a simple task.

Thank you for your time.

1
  • Class names should start with a capital letter -> Identification Commented Jun 12, 2015 at 8:12

2 Answers 2

1

use cp command to add a jar file

java -cp lib/myJar.jar myPackage.Program

also I believe you may need to import class where method person is in. I don't know how your hierarchy is so I can't help you with that.

Sign up to request clarification or add additional context in comments.

2 Comments

If person() is static then you can use: import ClassFromJar; and ClassFromJar.person(). If it is non static you need the same import and do ClassFromJar instance = new ClassFromJar(...); and instance.person().
Is the myPackage.Program the name of the jar plus the name of the program that is going to run?
0

You can add a jar to your classpath like this:

export CLASSPATH=$CLASSPATH:/path/to/your/myJar.jar

1 Comment

Note that this will set a global classpath which might be used by other Java applications. Not a good idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.