0

I have java project like this. I want to compile using javac(from command line). Can someone write exact example how to do this? It should take account all project files and all libraries provided under lib1 and lib2. All examples i have searched so far are useless

com.company.main
    Main.java
com.company.main.utils
   DoSomethingUtil.java

libraries

lib1/*.jar
lib2/*.jar
gogagubi
  • 965
  • 1
  • 15
  • 36
  • 2
    `mvn clean build` (or `gradle build`) – Turing85 Dec 26 '19 at 16:04
  • @Turing85 this is not a maven project. It's ejb based project – gogagubi Dec 26 '19 at 16:09
  • Oh sorry. I forgot: ``. Aside from that, those two technologies are orthogonal, not mutual exclusive. – Turing85 Dec 26 '19 at 16:15
  • http://web.mit.edu/6.031/www/fa17/projects/fb1/commandline.html – PM 77-1 Dec 26 '19 at 16:41
  • @Turing85 Or, since the jar files are locally available and download from repository is not needed, `ant` will work too. – Andreas Dec 26 '19 at 16:41
  • *"All examples i have searched so far are useless"* In what way were they useless? Show us what you've tried and explain how that didn't work for you. – Andreas Dec 26 '19 at 16:43
  • @Andreas Here are lots of options https://stackoverflow.com/questions/9395207/how-to-include-jar-files-with-java-file-and-compile-in-command-prompt. – gogagubi Dec 26 '19 at 16:48
  • javac -cp .:/jars/* com/template/*.java this should work in my case gives error that that files was not found. In my understanding this com/template/* cannot scan for nested files – gogagubi Dec 26 '19 at 16:51
  • Good link. I especially found [this answer](https://stackoverflow.com/a/43645985/5221149) to be matching your scenarios. So when you adapted it to your code, and ran it, what happened? **Edit** the question, show the command you tried, and the error it produced. That way we can help you figure out what you did wrong. – Andreas Dec 27 '19 at 00:23
  • @Andreas Thank for your responses. I found solution and pasted it as answer. I search for source and library paths first, then save them into files. The only difference between these files are that source files I save as a list and library files must be separated by ":" instead of new line. Then I can use them in javac command to compile .java files into .class files – gogagubi Dec 27 '19 at 07:27
  • Duplicate of [How to include jar files with java file and compile in command prompt](https://stackoverflow.com/q/9395207/5221149) – Andreas Dec 27 '19 at 11:25
  • check out this, maybe : [Compile and run Eclipse Project from command prompt](https://stackoverflow.com/questions/18902934/compile-and-run-eclipse-project-from-command-prompt) – shivang patel Jan 21 '20 at 13:20

1 Answers1

-1

This worked for me. Hope it helps to someone

//save into files
find  /javafiles-root-location/  -name "*.java" > build/source.txt
find  /libraries-location/* /libraries-location2/*  -name "*.jar" | paste -sd ":" > build/libs.txt

//then compile
javac @build/source.txt -d build/compiled/ -cp @build/libs.txt
gogagubi
  • 965
  • 1
  • 15
  • 36