Reputation: 3843
I'm doing a Java Project in Eclipse and I wanted to know how to compile these files manually. Right now, Eclipse does the building and running part and I would like to do it manually as we have to submit only the .java files. Now, I know that we have to use the javac
and java
command but these are throwing up exceptions from Java. So, here is what I have:
Assume the Eclipse project is named as Prj1. So the root directory is Prj1. This has 4 folders, .settings
, bin
, doc
and src
. There are also 3 files named .classpath
, .project
and javadoc.xml
. I also have a text file a.txt
in this root folder which is read by my java program (not as an input but somewhere in the middle of the execution, the file is opened and its contents are read). The src
folder has 5 class files in a package. That is, the src
folder has one folder called package1
and inside this, there are 5 class files.
So, how should I build this from the terminal with the javac
command and in which folder should I be? Also, where will the bin files be generated and where should I place the a.txt
text file which is read during run-time? I am unable to do it on my own. Please help.
Upvotes: 2
Views: 3464
Reputation: 2972
You could use maven as a build tool. The m2e plugin provides easy eclipse integration. You can then create a new maven project from eclipse or create it from the command line and import it as a maven project into your eclipse workspace.
Maven will also make your dependency management more easy.
There are of course alternative build tools, like ant or gradle
UPDATE: regarding the text file: you can treat it as a classpath resource. In eclipse it resides in a source folder. Name it 'resources' for example. From your code refer to it like
InputStream stream = Main.class.getResourceAsStream("/a.txt");
On the command line just copy the text file into the bin folder.
Upvotes: 1
Reputation: 1503859
It sounds like you should be "in" the src
folder and compile it with:
javac -d ../bin package1/*.java
The -d
argument specifies the root output directory for classes - the compiler will create a directory hierarchy based on the packages in the source files.
Upvotes: 5