views:

2510

answers:

3

I have the following in a java file (MyRtmpClient.java):

import org.apache.mina.common.ByteBuffer;

and ByteBuffer is inside a JAR file (with the proper directory structure of course). That jar file and others I need are in the same directory as the .java file.

Then I compile with the line:

javac -cp ".;*.jar" MyRtmpClient.java

But I get the error:

MyRtmpClient.java:3: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;

How can I include jar files in my project?

A: 

try including the jar file in your command line so :

javac MyRtmpClient.java ByteBuffer.jar

blispr
No, definitely not. "Usage: javac <options> <source files>"
Michael Myers
I'll try. But there are many of them. I dont like the idea of being forced to include all jar files one by one.
+2  A: 

javac does not understand *.jar in the classpath argument. You need to explicitly specify each jar. e.g.

javac -cp ".;mina.jar" MyRtmpClient.java
Mark
Yes, * is usually interpreted by the shell, but here it doesn't get a chance.
Michael Myers
yes, javac does understand *.jar in the classpath argument.
cd1
I tried using *.jar on Linux before writing my answer and it didn't work.
Mark
Depends on JDK version; see above.
Alex Feinman
I am using the latest update of JDK 1.6
Mark
So it seems to understand -cp *.jar if I remove the quotes but it does not understand -cp .:*.jar
Mark
+1  A: 

your command line is correct, but there are some considerations:

  • you must have javac >= 1.6, because only in that version the compiler parses the "*" as various JAR files.
  • you must be running Windows, because ";" is the path separator for that operating system only (it doesn't work on Unix).

I'm assuming that the JAR file has the proper directory structure as you stated.

cd1
Really? I didn't know that it would parse the *. I guess it's been a while since I compiled anything needing a classpath from the command line.
Michael Myers
Yours is probably the answer to my dilemma. I have JDK 1.5 :(
this is the source: http://java.sun.com/javase/6/docs/technotes/tools/windows/javac.html#options
cd1