Search code examples
openlayersoracle-jet

how do I add openlayers as a library to my oracle jet project?


I created an oracle jet project using ojet create, build, serve commands. Alternatively, I have also created the project using NetBeans 8.2 IDE. I am not able to add open layers as a library. I want to create a web application which would consist of maps.


Solution

  • Not sure why you are not able to add the library, as you haven't specified how you tried to add it and what was the error, if any.

    This is what I would do:

    1. After ojet create run the command npm install --save ol. This adds the library in your node_modules folder and also adds it to your package.json. If you don't want to add it to your package.json use only npm install ol.
    2. Navigate to scripts folder -> config folder -> oraclejet-build.js. See the commented lines 37 to 45? Uncomment those lines and add your own library paths, like this:

      copyCustomLibsToStaging: {
        fileList: [
         {
           cwd:'node_modules/ol/',
           src: ['*'],
           dest: 'web/js/libs/ol'
         }
        ]
       },
      
    3. You can now access your library by using the require module. Assuming you created an ojet project using a template, you can provide access to this library from the 'main.js' file.