开发者

Problem with file location when using Fixtures.loadModels("...")

I'm using the Play Framework yabe tutorial and came across a problem when adding tags. I'm not sure what code I added that开发者_如何学运维 caused the change, but now the Fixtures.loadModels(data.yml) piece of code searches for a file in .../some_folder/play-1.2.1/modules/docviewer/app/data.yml instead of .../some_folder/yabe_tutorial/conf/data.yml as it should.

Here's my code in the default package of /yabe_tutorial/app:

@OnApplicationStart
public class Bootstrap extends Job { 
  public void doJob() {
    if (User.count() == 0) {
        Fixtures.delete();
        Fixtures.loadModels("data.yml");
    }
  } 
}

Is there any settings I can use to change the directory that loadModels uses?

I'm new to this all, so I'd really appreciate some help. Thanks!


Sigurd is right. Fixtures.loadModels() looks for the yml file in Play.javaPath. Try renaming your data.yml file to some unique name like data-appname.yml and change the filename in your code as well.

@OnApplicationStart
public class Bootstrap extends Job { 
  public void doJob() {
    if (User.count() == 0) {
        Fixtures.loadModels("data-appname.yml");
    }
  } 
}

Worked for me.

Another option is to use Play.applicationPath which contains the location of root directory of the project

Fixtures.loadModels(Play.applicationPath + "/app/conf/data-appname.yml");


When you load Models within Fixtures class it scans all directories in Play.javaPath list. The normal behaviour is the javaPath contains "app" and "conf" directories of your application, i.e. root directory (Play.applicationRoot, by default is "."). Try to debug and see what javaPath contains in your case. Maybe this sample of code helps:

    @Override
    public void doJob() {

        if (User.count() == 0) {
            VirtualFile appRoot = VirtualFile.open(Play.applicationPath);
            Play.javaPath.add(0, appRoot.child("conf"));
            Fixtures.loadModels("data.yml");
        }

    }

It inserts into Play.javaPath new directory to the top of path. Anyway, this piece of code is quite ugly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜