Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing Java files outside of project in Eclipse

Tags:

java

eclipse

I have to write some little programs in Java for school, so I don't want all that stuff that Eclipse generates with a new project. The way I'm doing it now is this:

  1. $ touch myprog.java
  2. open and edit myprog.java in Eclipse
  3. $ javac myprog.java
  4. $ java MyProgClass

The problem is that Eclipse doesn't show warnings and errors while typing the code. It would also be nice if it would let me compile and run the file inside Eclipse (by doing what I do above in the working directory).

Is there any way I can make Eclipse do this?

like image 678
usr Avatar asked Jul 23 '26 12:07

usr


2 Answers

This is because Eclipse doesn't consider your .java file as something it should compile (and thus generate errors for)

You need to mark the folder containing myprog.java as a source folder. Here's how you do it:

Right-click on the folder and choose "Build Path" -> "Use as source folder".

like image 76
aioobe Avatar answered Jul 26 '26 01:07

aioobe


Well because now it's just a text file for eclipse and it isn't linked to java project.

Create new project and put myprog.java to /src folder in eclipse project.

Then:

$ javac workspace/yourpoject/src/myprog.java
$ java workspace/yourproject/bin/myprog

As a result copy only those 2 files and ignore the rest of project files if you want.

like image 37
Xorty Avatar answered Jul 26 '26 03:07

Xorty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!