1

I have seen several very similar questions on stackoverflow, but haven't come across anything that exactly matches my problem. I have a folder with several .java files, and another folder with two .jar files. I need to include both the jar files while using javac so that the entire project gets compiled at one go:

$: javac -classpath .:~/myjardir/*.jar ~/myprojectdir/*.java

But if I do this, only the first jar is recognized, and everything that depends on the second jar throws an error. Surprisingly, if I compile each program separately,

$: javac -classpath .:~/myjardir/oneofthejars.jar ~/myprojectdir/file1.java

then everything works fine. I have also compiled the project separately in Eclipse just to test the code and the jars. It is only when I try to use both the jars with -classpath in command line that I get the errors. Wildcard entries are supposed to work in JDK6, so I am at a loss here.

Chthonic Project
  • 8,216
  • 1
  • 43
  • 92
  • I would suggest you use a build tool like `ant` or `maven` to keep track of your dependencies and perform your build. AFAIK using wild cards works for the classpath for the JVM however it might not work for the `javac` – Peter Lawrey Nov 30 '11 at 15:32

3 Answers3

2

The class path wildcards don't work like they do in the Unix shells. The * means everything named *.jar in the directory. So you don't need to do *.jar but just *. The following should do what you want:

$: javac -classpath .:~/myjardir/* ~/myprojectdir/*.java

See Understanding class path wildcards in the Java SE 6 documentation.

lavinio
  • 23,931
  • 5
  • 55
  • 71
1

see the SO answer here but here's the relevant paragraph from the Java documentation:

Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/** specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.

Community
  • 1
  • 1
karakuricoder
  • 1,065
  • 8
  • 8
0

if you want multiple things in a classpath, you have to separate them by the classpath separator as far as I know. So ./lib:/lib/mylib would be a valid classpath on a unix system, I think the equivalent would be .\lib;\lib\mylib on a windows system. You don't have to specify every file, just the directories.

vextorspace
  • 934
  • 2
  • 10
  • 25