-1

I'm trying to make an Ebean ServerConfig as explained here: http://www.avaje.org/ebean/getstarted_programmatic.html

But, when in my project I create a new ServerConfig object, I cannot access the methods in it.

package controller;

import com.avaje.ebean.config.ServerConfig;

public class ormConfig {
    ServerConfig config = new ServerConfig();
    config.setName("mysql");
}

No expection, no hint from the IDE. Only an error from the compiler:

"Error:(14, 19) java: <identifier> expected"

https://gist.github.com/Szil/f65bc2d7180d2ae49ad5

Included the pom.xml in the Gist.

I have no idea where the problem is. A bit newbie in Maven and not exactly expert in Java, but simply creating a new object shouldn't be a problem most of the time.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Szilank
  • 26
  • 2

2 Answers2

1

You can't have arbitrary code directly inside a class. Only fields and methods declarations. Code like

 config.setName("mysql");

must go into a method or a constructor.

Also, classes conventionally start with an uppercase letter in Java:

public class OrmConfig {
    ServerConfig config = new ServerConfig();

    OrmConfig() {
        config.setName("mysql");
    }
}
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

You need to construct the config inside a constructor or a method as you cannot do this elsewhere. For example:

import com.avaje.ebean.config.ServerConfig;

public class OrmConfig {

    private ServerConfig config;

    public OrmConfig() {
        config = new ServerConfig();
        config.setName("mysql");
    }
}

By the way - which IDE are you using because this is definitely showing up in Intellij. :)

Christian Tapia
  • 33,620
  • 7
  • 56
  • 73
Mark Butler
  • 466
  • 3
  • 10