0

I'm having trouble getting my program to run in the command line. projectA has projectB and projectC on the build path.

I run this command:

javac -cp "projectB/src/":"projectC/src/" path/to/projectA/src/packagename/Program.java

This compiles fine. All the .java files in projectA, projectB, and projectC compile into .class files. However, when I run the command:

java -cp "projectB/src/":"projectC/src/" path/to/projectA/src/packagename/Program

I get the following error:

Error: Could not find or load main class path.to.projectA.src.packagename.Program

I have tried running the java command with many different derivatives of the -cp, paths, and from different working directories. Thanks for the help!

2 Answers 2

2

You need to have proper class path of projectA

java -cp "projectB/src/":"projectC/src/":"path/to/projectA/src" packagename.Program
Sign up to request clarification or add additional context in comments.

1 Comment

We provided the answer simultaneously, I'll +1 to share the love :)
1

With your command, javac thinks that the package is path/to/projectA/src/packagename/Program

You need to specify the fully qualified name (packagename.Program) and add the path in your classpath:

java -cp "projectB/src/":"projectC/src/":"path/to/projectA/src" packagename.Program

1 Comment

Thanks! That did it.

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.