How to run a single java file.

Answered

I'm working on a project which has many modules. Whenever I try to run a single file, it either builds/compile the whole project or build/compile the whole module.

In the image, you can see I have a file named "Dynamic.java". Whenever I try to run it, it builds the whole module "Chapter 08". I just want to run "Dynamic.java" but the compiler doesn't let me do so. It says "duplicate classes".

It is an obvious thing that "Inheritcance.java" and "Dynamic.java" has the same class name. But they aren't dependent on one another they have their own main. So I want to run them independently irrespective of how another file is written or whatever it has. Is it possible to do so?

4 comments
Comment actions Permalink

Hello,

You may remove "Build" action from "Before launch" section of run configuration.

1
Comment actions Permalink

I did as you said but sadly it didn't work and it shows the following errors.

the following error.

0
Comment actions Permalink

This is my "inheritance.java". See both have their own main then why I can't run them without any dependency.

0
Comment actions Permalink

Seems it's prohibited to have more than one class in file. Please try to put each class in separate file. Then run should work fine.

0

Please sign in to leave a comment.