mportiz08
mportiz08

Reputation: 10318

Why can't I compile my java file on cygwin, when it needs classes from a jar?

I'm trying to compile my class along with a provided .jar file which contains classes that my class will use.

This is what I've been trying:

javac -classpath .:WordSearch.jar WordSearchSolver.java

And this is the response:

WordSearchSolver.java:16: cannot find symbol
symbol  : class PuzzleWord
location: class WordSearchSolver
    public ArrayList<PuzzleWord> findwords()
                 ^
WordSearchSolver.java:18: cannot find symbol
symbol  : class PuzzleWord
location: class WordSearchSolver
    return new ArrayList<PuzzleWord>();
                         ^

2 errors

This is my class:

import java.util.ArrayList;

public class WordSearchSolver
{
    public WordSearchSolver(int size, char[][] puzzleboard, ArrayList<String> words)
    {

    }

    public ArrayList<PuzzleWord> findwords()
    {
        return new ArrayList<PuzzleWord>();
    }
}

WordSearch.jar contains:

PuzzleUI.class
PuzzleWord$Directions.class
PuzzleWord.class
Natural.class

(WordSearchSolver.java and Wordsearch.jar are in the same directory)

Am I missing something?

Upvotes: 0

Views: 5186

Answers (3)

Brian Agnew
Brian Agnew

Reputation: 272297

Although you're on Cygwin, I'm guessing that your path separator should be a semicolon, since the Java compiler/JVM will be running in a Windows environment.

javac -cp .\;WordSearch.jar ...

Note that the semicolon must be escaped to prevent interpretation by the Cygwin shell (thanks to bkail below)

Upvotes: 3

mportiz08
mportiz08

Reputation: 10318

It ended up being a combination of semicolons and quotation marks.

javac -classpath ".;WordSearch.jar" WordSearchSolver.java

Thanks everyone for pointing me in the right direction!

Upvotes: 0

akf
akf

Reputation: 39485

You aren't importing any of the classes from your WordSearch.jar in your WordSearchSolver class. You need import statements at the top of this class including their package.

Upvotes: 1

Related Questions