-2

Suppose one has a java project which consists of several packages, subpackages etc, all existing in a folder "source". Is there a direct way to copy the structure of the folders in "source" to a "classes" folder and then recursively compile all the .java files, placing the .class files in the correct locations in "classes"?

Koul
  • 135
  • 4
  • also : there is no "classes file", there will be A class file for EVERY .java-file - and one MAY aggregate then into one single JAR-file – specializt Nov 16 '14 at 14:23

2 Answers2

1

For larger projects a recommend using a build tool like Maven or the newer and faster Gradle. Once you've configured one of them for your needs, it's very easy to do the job by calling mvn build or gradle build.

If these tools seem to heavy for your purpose, you may have a look at Ant. A simple ant example:

<project default="compile">
<target name="compile">
    <mkdir dir="bin"/>
    <javac srcdir="source" destdir="bin"/>
</target>
</project>

and then run ant from the command line. See this thread for further information.

Community
  • 1
  • 1
TobiasMende
  • 701
  • 3
  • 8
  • Thank you Tobias, your answer is exactly what I was looking for! In the past I had used GNU make as a building tool for other tasks. Do you think it makes sense to use make to manipulate java files, or is it too outdated compared to the building tools you recommended? Thanks once more! – Koul Nov 16 '14 at 14:38
  • Make is a very flexible build tool usable for building everything. Of course you could build your java project with `make` but than you would and up configuring everything on your own. Build tools like Gradle, Maven and Ant are developed especially for Java projects though they could also be used for projects. In most cases, it's easier to use these tools because they provide a specific structure and some pre configured tasks and can be extended by plugins according to your needs. Most Java IDEs provide support for Maven and Gradle and especially the documentation of Gradle is awesome. – TobiasMende Nov 16 '14 at 14:40
  • I see; make is more of an all-purpose tool. Thanks for the info. – Koul Nov 16 '14 at 14:44
0
Community
  • 1
  • 1
specializt
  • 1,836
  • 15
  • 22