0

I have been away from Java stuff for quite sometime, need some help about basic stuff.

I have the following project structure :

enter image description here

There are no manifest files etc, its just a raw folder structure.

I wanted to know command to compile these java classes from root folder Data Structures - Java and command to execute compiled classes.

I did try

javac -d build com.codesuman.datastructures.Main

This worked first time but failed in next attempt.

Thanks in advance.

BeingSuman
  • 3,015
  • 7
  • 30
  • 48

2 Answers2

1

Main class seems to be inside linear folder
This should do the job javac -d build com.codesuman.datastructures.linear.Main

IQbrod
  • 2,060
  • 1
  • 6
  • 28
1

I don't see how that could work, even a single time :

javac -d build com.codesuman.datastructures.Main

In javac, the last argument is "source files". It has to specify location of java source to compile in terms of filesystem location : that is file or directory.
But that com.codesuman.datastructures refers to a java package. Something like that is expected : com/codesuman/datastructures/Main.java.

So, to compile that class in the build directory, do that :

javac -d build com/codesuman/datastructures/Main.java

But if Main.java relies on other classes, which looks possible according to your snapshot, you also need to compile these classes.
So a more idiomatic approach in this case is :

javac -d build com/codesuman/datastructures/*.java

But beware the subfolders are not compiled.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
  • Hmm that makes sense now & it worked when i execute `javac` command from src folder. To add what should i do if i want to build from outside src folder say i want to be in root folder and execute `javac` command ? – BeingSuman Aug 19 '19 at 12:58
  • You can specify the classpath with `-cp src` for example. – davidxxx Aug 19 '19 at 13:03
  • My understanding was to use -cp for `java` command. My question was how to use `javac` command directly from outside `src` folder. Thanks. – BeingSuman Aug 19 '19 at 13:10
  • 1
    but `cp` is for both `javac` and `java`. You have the compile time classpath and the runtime classpath. So for your question, use `cp` too. – davidxxx Aug 19 '19 at 13:11
  • Thanks @davidxxx, will go through documentation. – BeingSuman Aug 19 '19 at 13:12
  • 1
    You are welcome. And you also have `-sourcepath`. https://stackoverflow.com/questions/2441760/differences-between-classpath-and-sourcepath-options-of-javac – davidxxx Aug 19 '19 at 13:15