How to wildcard include JAR files when compiling?

Viewed 96142

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?

9 Answers

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, the path separator on Unix is ":").

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

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

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

Probably below syntax will work on windows dos command

javac -cp ".;first.jar;second.jar;third.jar" MyRtmpClient.java

try including the jar file in your command line so :

javac MyRtmpClient.java ByteBuffer.jar

Related