Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile & run a project-less file in Netbeans?

Tags:

netbeans

Netbeans, indeed any Java compiler and executor, needs to know the classpath to compile and run a file. When you just open a file in Netbeans, you do not tell it any of that information. When you set up a project, that process tells Netbeans where the Java resources are.

Yet other IDEs can easily do this. It's not good practice, but it's simple and quick for "fooling around".

Is there any way to compile & run a file, that doesn't belong to a project, in Netbeans?

edit: The options are greyed out if the file doesn't belong to a project.

like image 638
Dennis Avatar asked Apr 03 '09 20:04

Dennis


2 Answers

Your best option with NetBeans is just to create a dummy "try stuff" project that you know will never contain a shipping product but will allow you to experiment without having to create a new project every time.

You could even collect code snippets in different classes this way. If you add a main() method to each experimental class, you have a way to run them all in the IDE just by changing what you have set for the main project class. This is what I do and it works pretty well.

like image 60
ssakl Avatar answered Nov 16 '22 03:11

ssakl


Why not using 'create new project with existing sources' which can be done for Java, Ruby, ... projects?

You can do so and netbeans will create only a nbproject folder within your project's dir and all should be fine.

like image 20
Karussell Avatar answered Nov 16 '22 04:11

Karussell