0

I have 5 .java files in src folder and many dependent jars in lib folder While Compiling the .java files with the jars i am facing error as,

src\Grapher.java:12: error: package org.jfree.chart does not exist import org.jfree.chart.*;

My directory sturcture is,
C:\Grapher\src*.java
C:\Grapher\lib*.jar

I am using the commond javac -cp .;lib/*.jar src/*.java

GangaRam Dewasi
  • 631
  • 7
  • 11
  • Looks actually good. Have you tried listing the jar files by name; instead of using "*"? – GhostCat Jul 26 '17 at 08:11
  • No !! because there are many dependent different jars for different java files – GangaRam Dewasi Jul 26 '17 at 08:13
  • Then just go for a simple experiment and add the freechar jar with its full name and see if that changes anything. – GhostCat Jul 26 '17 at 08:15
  • I don't know if your use of wildcard will work. Is that windows? What exactly? In POSIX shells, I expect your `.;lib/*.jar` to fail (because of the way wildcards expand) but I am not sure of your environment... – MariusSiuram Jul 26 '17 at 08:16
  • @MariusSiuram In windows, expansion is done by the application, isnt it. Windows wouldnt know how to expand / - and javac finds it way to the files in src – GhostCat Jul 26 '17 at 08:18
  • 1
    Please be aware that this is a very low level approach. Going for build tools like Maven or Gradle is the contemporary way. – J Fabian Meier Jul 26 '17 at 08:20
  • @JFMeier There is still some merit in understand *how* things work on the most basic lowest level. I think it is actually good practice to start on that level, and only turn to tools such maven or gradle after figuring *what* those tools do for you. – GhostCat Jul 26 '17 at 08:40
  • 2
    @GhostCat I just wanted to point out that this is not the way you should work for productive code. – J Fabian Meier Jul 26 '17 at 08:51
  • Sure thing ... it is not like a flagged your comment for "not constructive" or so ;-) – GhostCat Jul 26 '17 at 08:52

1 Answers1

0
  1. Make sure you have JFreeChart jar in your lib folder
  2. You have to wrap arguments of -cp to brackets
  3. You didn't provide sourcepath.

Try this:

javac -classpath "lib/*" -sourcepath src src/*.java

Note: this will work only if your java files are located exactly in src folder. In case if you have package declaration in your classes you have to specify package structure.

eg: src/com/company/*.java

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
  • To my knowledge usage of -sourcepath is optional. And when telling to compile all files in src, (and no sub packages are used) - what is the point of using it? – GhostCat Jul 26 '17 at 08:32
  • According to the documentation http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html the sourcepath could be skipped in case if classpath includes folder with sources. But it is not the case here. – Sasha Shpota Jul 26 '17 at 08:39
  • @GhostCat you're right, tried locally - it works. Could you hint me the link on documentation which explains why it can be skipped. – Sasha Shpota Jul 26 '17 at 08:45
  • I just found a statement "is optional" here: https://stackoverflow.com/questions/2441760/differences-between-classpath-and-sourcepath-options-of-javac – GhostCat Jul 26 '17 at 08:48
  • @OleksandrShpota Thanks!! javac -classpath "lib/*" -sourcepath src src/*.java worked perfectly. – GangaRam Dewasi Jul 26 '17 at 09:21
  • @Oleksandr Shpota what if i want to create a war file from the above file that i have ? – GangaRam Dewasi Jul 26 '17 at 10:57
  • Try to follow one of tutorials, for instance http://www.avajava.com/tutorials/lessons/how-do-i-create-a-war-file-using-the-jar-command.html – Sasha Shpota Jul 26 '17 at 18:06