File location issue when using Fixtures.loadModels ("...")

I am using the yabe Play Framework language tutorial and have encountered a problem adding tags. I'm not sure which code I added that caused the change, but now the Fixtures.loadModels (data.yml) code snippet is looking for the 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 be.

Here is my code in the default package / yabe _tutorial / app:

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

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

I am new to this, so I am very grateful for the help. Thanks!

+6
source share
2 answers

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

 @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 the project root directory

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

When loading models in the Fixtures class, it scans all the directories in the Play.javaPath list. Normal behavior: javaPath contains the application directories and the "conf" of your application, i.e. The root directory (Play.applicationRoot, the default is "."). Try debugging and see what javaPath contains in your case. Perhaps this sample 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");
         }

     }

Inserts a new Play.javaPath directory at the beginning of the path. Anyway, this piece of code is pretty ugly.

0
source

Source: https://habr.com/ru/post/890014/


All Articles