-2

I have trying to compile java files at the windows command line using commands such as:

java myProg once I have used javac to create class files.

Problems arise when I use packages with a number of source files.

Often but not always I get main not found errors even though a main exists.

I am not quite sure what some of the directives mean and that is why it seems hit or miss.

Question what does -cp mean exactly? java -cp src\myDirectory.myfile

sometimes I see:

./ infront of source eg .\src\myDirectory.myfile

on other sites I have found

% javac -cp .;stdlib.jar MyProgram.java

% java -cp .;stdlib.jar MyProgram

while compiling a jar library with java source files

what doesthe ".;" mean?

basically how do I compile three java source java files in one package at the windows command line and what does -cp and .; mean?

soorapadman
  • 4,451
  • 7
  • 35
  • 47
Timothy Lawman
  • 2,194
  • 6
  • 24
  • 33
  • 1
    http://www.sergiy.ca/how-to-compile-and-launch-java-code-from-command-line/ take a look at this. I would still suggest that you use Ant or Maven – jtothebee Oct 13 '15 at 08:35
  • 1
    Have you seen this: [How do I run java program with multiple classes from cmd?](http://stackoverflow.com/questions/20365885/how-do-i-run-java-program-with-multiple-classes-from-cmd) – pelumi Oct 13 '15 at 08:41
  • It is a good starting point - what does the line if you have any other classes in the project , they should be automatically compiled and placed in the correct folders mean? Doe sit mean I should place them in the folders or the compiler will do it for me? This is the crux of the problem , I have three .java class files not one and this example only addresses one .java file. – Timothy Lawman Oct 13 '15 at 08:43
  • -cp is classpath. `.` means current directory and `;` is a separator of locations you are telling `javac` to look for in the classpath – Mr Moose Oct 13 '15 at 08:44
  • Doe sthat mean ; means you are looking for more than one file in a folder? – Timothy Lawman Oct 13 '15 at 08:46
  • To compile all files in a directory you use: `javac *.java` that's a wildcard that means run the `javac` command all all `.java` files in the specified directory. – pelumi Oct 13 '15 at 08:47

2 Answers2

0

-cp means class path if I'm not mistaken. try reading the following java docs

-classpath path Specifies the path javac uses to look up classes needed to run javac or being referenced by other classes you are compiling. Overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by semi-colons. It is often useful for the directory containing the source files to be on the class path. You should always include the system classes at the end of the path. For example:

   javac -classpath .;C:\users\dac\classes;C:\tools\java\classes ...

https://www.cis.upenn.edu/~bcpierce/courses/629/jdkdocs/tooldocs/win32/javac.html

UnnameDSoS
  • 113
  • 1
  • 12
-1

Answering your question directly, -cp means classpath or path.

Details on commandline arguments used while compiling and running a Java application can be found here: javac - Java programming language compiler

Extracting the description of -cp from that page:

-cp path or -classpath path:

Specify where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, the user class path consists of the current directory. See Setting the Class Path for more details.

. means the current directory.

To compile multiple files in a directory use the following:

javac *.java // compliles all java files in the dir
java MyClass // runs the particular file

There are also a bunch of other related questions that should help you resolve this:

  1. How to run a java program from the command line
  2. How do I run java program with multiple classes from cmd?
  3. Problems running a java program from the command line interface
  4. Can't run multiple-class program from command line using packages
Community
  • 1
  • 1
pelumi
  • 1,530
  • 12
  • 21