1

I try to develop a utility project in SAP WebIDE to share useful utility classes with other developers. Let's call this a BaseProject. In my CustomProject I want to use a reference to this BaseProject and use e.g. the formatter.

Therefore I created a UI5 Application project in WebIDE called

com.company.base

and a custom project

my.custom.app

In the com.company.base project I have the following folder structure:

com.company.base
+--- webapp/
     +--- formatter/
          Formatter.js
     Component.js
     library.js
     manifest.json
neo-app-json

The library.js looks like this:

sap.ui.define(["jquery.sap.global", "sap/ui/core/library"
], function(jQuery) {

    "use strict";

    sap.ui.getCore().initLibrary({
        name: "com.company.base",
        version: "1.0.0",
        dependencies: ["sap.ui.core"],
        types: [],
        interfaces: [],
        controls: [
            "com.company.base.formatter.Formatter"
        ],
        elements: []
    });

    return com.company.base;

}, /* bExport= */ false);

I deployed the base project to hcp as

comcompanybase

In my custom application I added the following route to the neo-app.json

{
    "path": "/comcompanybase",
    "target": {
        "type": "application",
        "name": "comcompanybase"
    },
    "description": "Base Project"
},

and did the registration inside of the init-Method of component.js like this:

jQuery.sap.registerModulePath("com.company.base", "/comcompanybase/webapp");
jQuery.sap.require("com.company.base.Component");

Finally, I'm able to use the formatter inside of a controller of the custom app like this:

sap.ui.define([
    "my/custom/app/controller/BaseController", 
    "com/company/base/formatter/Formatter"
], function(BaseController, Formatter) {

    "use strict";

    return BaseController.extend("my.custom.app.controller.Master", {
        formatter: Formatter,
        onInit: function() {
            //some coding
        }
    });
});

Every time I start the application for the first time the reference is not found. The second time everthing works.

Also I have to deploy the application to hcp after every change. Is there a way to use the lokal workspace of WebIDE for a reference? I tried to navigate upwards with ../../ but this does not worked for me.

srz
  • 129
  • 1
  • 1
  • 11

1 Answers1

0

WebIDE project: Run -> Run configurations -> Create new configuration (with needed parmeters) and in addition in the "Advanced settings" check the checkbox "Use my workspace first".

This should prevent you from a need of deploying after each change.

Andrew Naumovich
  • 1,441
  • 1
  • 12
  • 15
  • Thix fixed the problem with the deploying. But the error while loading the first time stimm exists. Any idea where this comes from? – srz Jun 29 '17 at 13:29
  • Did you add the dependency for your library in manifest of the consumer app? – Andrew Naumovich Jun 29 '17 at 15:25
  • No, I added the reference only in neo-app.json. Thanks for the hint, I guess adding it as library dependency in manifest.json solved the problem. – srz Jul 04 '17 at 08:46
  • if it works for you, then you can accept this answer ;) – Andrew Naumovich Jul 05 '17 at 10:47
  • I tried this, but an error occured that library.js couldn't found – srz Jul 06 '17 at 12:52
  • "I tried this, but an error occured that library.js couldn't found" - cannot do anything with this information, if you want this issue to be solved, then please provide the examples how you tried, which error occured and when? How did you try to fix it? – Andrew Naumovich Jul 10 '17 at 08:28
  • In my consuming app, I added the library in manifest.json as a library dependency. After that, my consuming application try to fetch the library.js from the base project. This file couldn't found. Is a library project the correct project type for this use case. – srz Jul 11 '17 at 08:14
  • Please provide the coding (how you added that dependency to manifest) – Andrew Naumovich Jul 11 '17 at 12:26