Emacs: new line and automatic indentation in Java mode - emacs

I am new to Emacs. The Emacs that I am using now is not performing automatic indentation in Java mode. My problem can be best exemplified by the example below. Let | represent the cursor.
When I type:
public class Testing{
public static void main(String[] args){|}
}
and press ENTER , the code becomes:
public class Testing{
public static void main(String[] args){
|}
}
But this is not what I want. What I want is this (new line with auto-indentation):
public class Testing{
public static void main(String[] args){
|
}
}
Can someone suggest what code I should add to the init.el file ?

Did you already try the following to indent upon ENTER?
(global-set-key (kbd "RET") #'newline-and-indent)

Related

Way to find all affected locations by variable

I want to find code lines, where a certain property can get.
Consider I have property holder class and in java editor look to some setter method. In code is property readed and setted to entity. And before save to database, do validation on server side. So I want see from client.propertyHolder.setter to server.entityValidator.getter
Simple example
public class Main{
public static void main(String[] args) {
Holder h = new Holder();
h.setHolder("Something"); // Here i want use plugin
Entity e = new Entity();
e.setName(h.getHolder());
// Consider this is on server side in validator and call only if annotation validation is OK
Assert.assertTrue(e.getName().length() > 0)
}
}
public class Holder{
public String holder = null;
public void setHolder(String holder){this.holder = holder}
public void getHolder(){return holder}
}
public class Entity{
#javax.validation.constraints.NotNull
private String name = null;
public void setName(String name){this.name = name}
public void getName(){return name}
}
So i should get lines
e.setName(h.getHolder());
Assert.assertTrue(e.getName().length() > 0)
and be nice if NotNull anotations too
Is there a way, how to achive this? Some good free eclipse-plugin maybye?
Thanks for help. Pavel

Automaticle replicate microservices with Spring Cloud Netflix

I have multiple Spring Cloud microservices. I want the automatic replication of microservices to be done when microservice cannot manage to do its work.
I tried to find any solutions but I found only this: here. This solution cannot be applied to my problem as it describes only the case when we have a certain number of microservices.
I will be very grateful if you give me some examples to help me with this problem.
UPDATE: I've several microservices
Eureka:
#SpringBootApplication
#EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args){
SpringApplication.run(EurekaApplication.class, args);
}
}
GatewayApplication:
#EnableZuulProxy
#EnableEurekaClient
#SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
FirstSybsystemApplication:
#SpringBootApplication
#EnableEurekaClient
#EnableFeignClients
public class FirstSubsystemApplication implements CommandLineRunner{
public static void main(String[] args) {
SpringApplication.run(FirstSubsystemApplication.class);
}
#Override
public void run(String... args) throws Exception {
}
}
I want to make a high load on FirstSubsystemApplication and to launch its copy automatically.

Could not find the preLaunchTask 'npm'

I'm trying to write a simple Hello World console application using VS Code. Following is what I have in my program.cs which I have created
using system;
namespace MySpace
{
public static class MyClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello");
}
}
}
When I hit F5, it says "Could not find the preLaunchTask 'npm'."
What am I doing wrong??

Running a public static void main in Groovy Eclipse

Sorry Groovy Noob here:
Here is my Groovy Class -
class MyClass {
static void main() {
println("Hello World");
}
...
How do I run this classin Eclipse STS? I want to keep the main method. I do not want to change this to just a script.
Thanks
To initiate a method, main you must pass in a string array (String[] something). Use the following.
public static void main(String[] args)
{
System.out.println("Hello World")!
}
Remember... a Groovy class is a Java class. All you need to do is right-click -> Run as -> Java application.

How to make out.println() method working in a simple java file without using System Class reference?

public class ABC{ public static void main(String[] args) { out.println("Hello"); } }
This works, though static imports are not generally considered a good thing in java.
import static java.lang.System.out;
public class ABC {
public static void main(String[] args) {
out.println("hello");
}
}