if you choose maven as project management then you really need to do this "maven way".
Eclipse creates a project based on the class path specified in the project properties and does not apply to the maven compiler plugin class path. "mvn compile" is only controlled by the configuration of the compiler plugin.
Typically, these “temporary” changes are handled by JVM parameters added to the maven target (the maven plugin / Mojo target that you use from cmd) that you create (custom) and save in “Run as”> Run configurations. I use commandline (shell), not m2eclipse for maven. changing options are faster for me.
To find out which parameters you can use, you can specify a specific Mojo (maven plugin) in your maven dependencies (only temporarily) and look at its sources directly in eclipse, you can see the parameters that can be specified using the "-D" JVM. Or you can check the documentation.
The compiler plugin has a parameter private Set<String> excludes = new HashSet<String>(); but, unfortunately, the collection parameters cannot be specified as JVM parameters ... Thus, the only option left is to configure the plugin declaration in pom.xml.
Then there are also profiles, but they are not useful for this case.
To summarize, your requirement is quite rare; excluding the java class from compilation is not a normal requirement.
I hope this helps
lisak source share