Java in Eclipse: Why must I always use a project? - eclipse

I am just learning Java and use Eclipse. I have a question that I can not find an answer to.
Why does eclipse require me to use a project? I am using eclipse now to learn Java,
and that means compiling my source.
Problem being that when I add another source file Eclipse
compiles both applications. This means (and I could be very wrong here) I need to create a project
for every new program I write.
Why can I not just create and compile programs without a project?

What are you missing is called 'Run Configurations'.
Create a project.
Write your multiple programs within this one project. (Presumably, these programs might share some class files or other resources.)
Each of your programs will contain a class file with an entry point, for example, a main() method.
Open this class file and right-click. Select 'Run As', then the most appropriate option.
Following this you will see your Run Configurations here:
Click the drop-down icon and select the Run Configuration that you want to execute. Select 'Run Configurations...' if you want to add program arguments or making other changes.

Related

how to compile and run one single scala file without building whole project within intellij

I have several scala object in my project, sometimes I would like to run one single object whch has no dependency on any other object in the file (just want to see how it would behave before merging it into the whole project), but every time I click on "Run 'XXX'" (where xxx is the name of the object I would like to run, "hello world" for example), intellij tried to build the whole project, actually I just wanted to build and run the single scala object, like "helloword.scala".
I searched a lot and mostly the questions are about Java, if someone wants to run single Java class, then he can right click in the editor zone, then choose the "Run xxx.main()", but in my case ,I just can find the "Run xxx",
someone said that cancel 'make' in run/debug configuration, but how and I didn't find 'make' button in the configuration.
so, anybody have an idea how to compile/build/run just one single scala object/file at one time in intellij?
BTW I am using the intellij idea 2019.1 and the project is based on maven.
Try removing Build action from Before launch section of the corresponding Run/Debug Configuration like so
Edit the Run/Debug Configuration for the Application configuration type
Go to Before launch section
Remove Build action by clicking on the minus - button
You can test this out by creating two apps
// Run.scala file
object Run extends App {
println("woohoo")
}
and
// RunBroken.scala file
obct RunBroken extends App {
ptln("boom")
}
Create run configuration for Run.scala by following above instructions, and it should run despite there being a syntax error in RunBroken.scala.
You can create a Scratch File.
Simply search for Scratch file in the actions search
And search for Scala in the languages dialog: (I'm using Java as an example, since I don't use Scala.)
This will create a new scratch which is accessible under Scratches and Consoles -> Scratches in the Project view.
As you can see here, there are Syntax Errors in a Project file
and yet, the Scratch file will compile and run:

Run Xtext product directly

I am using on Xtext to create my own language. My product uses Xtend to generate from my language to Java and I can right click on the generated Java file to run it. But I would like to right click on my own language file and run it directly, then IDE will go to generated Java file to run.
To do that, I have created a command and contribute to context menu.
What should I do next to make IDE goes to Java file and run it?
Thanks
See http://www.eclipse.org/articles/Article-Java-launch/launching-java.html

Launch and debug a single script in PyDev

I am a beginner in using Eclipse and PyDev (Aptana Studio 3). I am not used to and i don't understand the workflow in such big IDEs as Eclipse.
I have a simple task: i have a simple Python script, which i want to open and run in Eclipse, having its output in Eclipse console. Or debug it.
Until now i used another IDE called Eric4, which allowed me to do what i want - open a file and run immediately, without creating a project or setting up launch configurations.
Is this possible in Eclipse, or i have to create a project for each file i want to run or debug? I want to understand how it works.
I guess i understand that creating a project is needed at least for settings up the paths (PYTHONPATH), but if it's a single script - somehow to use by default the current directory?
For example i have a folder called snippets where i keep a lot of python scripts which demonstrate some functionality. How do i open these files one by one and run them?
Most of my coworkers launch python scripts in a separate console - python my_scipt.py.
You need to have at least one project with the configuration you want (i.e.: syntax type, interpreter), then, open the file you want to run and press F9.
If it's an external file -- i.e.: a file that's not under a project in Eclipse -- it'll ask you to associate a project with the launch to get the needed information for the launch, but the file doesn't really have to be in the project (note that you can drag external files from your filesystem into Eclipse to open them).
I suggest you follow the steps on the getting started: http://pydev.org/manual_101_root.html (it guides you to configuring PyDev and explains how to do a run/debug session).

How to get an Eclipse CDT project to auto-reload a .c file that has been externally modified

I'm using a ruby script to help generate a .c file based on another .c file (for a test harness called Unity).
The script runs using the pre-build option, updates the file, but the cproject doesn't see the upadted file as being touched so doesn't rebuild with it.
Using F5 updates it but I'd like to do this manually.
I can't see how to make this happen.
I had the same issue generating a C file from a Python script.
What I ended up doing is to create a special Builder for that file.
If you go to the project properties, go on the Builders tab and click New. Then select Program. You can fill all the information there. The important part is to go on the Refresh tab and select Refresh resources upon completion.
I also found it useful to unselect the stdio ("Allocate Console" in Build Options tab) so that it doesn't clear the console after a build.
the only drawback of that method is that the Builder doesn't pick-up dependencies and is called all the time.

Eclipse adding your own build command

I am new to eclipse and wanted to do the following:
Use my custom build commands with eclipse. Until now I only saw make all. I use a shell script for building my project; how can I use that in an Eclipse environment?
When I create a new project with the existing source code, it doesn't add the files, without building the code and if code fails to build (because I generally don't have make all).
How do I resolve this issue?
You can add a custom builder in the "Builders" category of the project properties.
project->properties->builders->new
there you can also deactivate the default eclipse builders..
hope that helped
In addition to what smeg4brains said and assuming that you are using the CDT plugin you can go to:
project -> properties -> C/C++ Build
Uncheck Use default build command on the Builder Settings tab and replace make with e.g. scons.
On the Behaviour tab you can then specify the target to call for the Build and Clean phase.
To resolve your second issue open the Project menu and uncheck Build automatically.
This will prevent Eclipse from building the project when it thinks it is necessary.
If you want to add other your own commands then the easiest way is to write Ant file for your project so by clicking once you can execute all your commands.To see how to write Ant file click here
I was able to do something similar to have protoc run on my .proto files. I did it by adding a "Make Target" to the project.
A lot of stuff in Eclipse you can get around using Ant, which are XML scripts, and there is also a ANT project builder which uses those. If you don't like to mess with frankly quite touchy GUI options, just write a build.xml and use ANT build as the project builder.