Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:21:16+00:00 2026-06-15T11:21:16+00:00

I have a eclipse plugin contributing a project nature requiring the jsdt javaScriptNature. I

  • 0

I have a eclipse plugin contributing a project nature requiring the jsdt javaScriptNature. I now like to add a javascript library contained in my plugin to the includepath of the project programatically. Is there a way i can do this?

I read something about JsGlobalScopeContainer and JsGlobalScopeContainerInitializer and tried them but that seems very confusing. I just want to add a library containing some .js files from my plugin. I just can’t get my head around this concept.

This is what i came up with so far:

IJavaScriptProject jsProj = JavaScriptCore.create(p);
Path pa = new Path("/src/de/otris/eclipse/portalscripting/psLibrary/library.js");
IIncludePathEntry entry = JavaScriptCore.newProjectEntry(pa);               
IIncludePathEntry[] ipaths = jsProj.getRawIncludepath();
IIncludePathEntry[] newpaths = new IIncludePathEntry[ipaths.length +1];
System.arraycopy(ipaths, 0, newpaths, 0, ipaths.length);
newpaths[ipaths.length] = entry;
jsProj.setRawIncludepath(newpaths, null);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:21:16+00:00Added an answer on June 15, 2026 at 11:21 am

    I finally found a way to add my library directly from my plugin. Allthough the answer of Eugene wasn’t to wrong, it lacked some explainations. I’ll try to show how to do this.

    If you want to add a library containing several files you can do it this way:

    1. Create a Class extending JsGlobalScopeContainerInitializer
    2. Contribute an extension to the extension point org.eclipse.wst.jsdt.core.JsGlobalScopeContainerInitializer
    3. Add an IIncludePathEntry, pointing to the JsGlobalScopeContainer using its id, to the Project that you want to use the library in

    1. Create a Class extending JsGlobalScopeContainerInitializer

    There are a few very confusing tutorials out there (including the one on the eclipse wiki) that at first made it harder to understand this. I came up with something like the following:

    [... package and imports ommited ...]
    public class LibInitializer extends JsGlobalScopeContainerInitializer {
    
        private static final String LIBRARY_ID = "com.testvendor.testplugin.library";
    
         public IPath getPath() {    
             return new Path(LIBRARY_ID);
         }
    
        @Override
        public LibraryLocation getLibraryLocation() {   
            return null;
        }
    
        @Override
        public String getDescription() {
            return "Test Library";
        }
    
        @Override
        public String getDescription(IPath containerPath, IJavaScriptProject project) {
            return getDescription();
        }
    
        @Override
        public IIncludePathEntry[] getIncludepathEntries() {
    
            try {
                //get the Bundle object of the plugin
                Bundle bundle = Platform.getBundle("com.testvendor.testplugin");
                //get the java.io.File object corresponding to the root of the bundles installation directory
                File bundleFile = FileLocator.getBundleFile(bundle);
                //add the location pointing to the library relative to that bundle root
                File libraryLocation = new File(bundleFile, "bin/com/testvendor/testplugin/library/");              
                //create a Path object from it
                IPath pa = new Path(libraryLocation.getAbsolutePath());
    
                /* create an IIncludePathEntry of the type "library" from this path
                my library only contains one folder (for now) so this is it */
                IIncludePathEntry entry = JavaScriptCore.newLibraryEntry(pa, pa, pa);
                //put the entry (or entries if you had more) into an array and return
                IIncludePathEntry[] entries = {entry};
                return entries;
    
            } catch (IOException e) { 
                e.printStackTrace();
            }       
            return null;
        }   
    }
    

    The most interesting part is the method getIncludepathEntries() where the actual entries will be retrieved from the container. Since an IIncludePathEntry will not work with an URL of the “file://” pseudo-protocol the method “toFileURL” suggested by Eugene will not work here.

    2. Contribute an extension to the JSGlobalScope… extension Point

    To tell Projects containing an container entry with the id com.testvendor.testplugin.library the easiest way is to contribute to the extension point *org.eclipse.wst.jsdt.core.JsGlobalScopeContainerInitializer** like this:

    <extension point="org.eclipse.wst.jsdt.core.JsGlobalScopeContainerInitializer">            
      <JsGlobalScopeContainerInitializer                                          
         id="com.testvendor.testplugin.library"                                                        
         class="com.testvendor.testplugin.library.LibInitializer"/>                           
    </extension>
    

    Where class of course refers to the JsGlobalScopeContainerInitializer from step 1.

    3. adding the IIncludePathEntry to the Project

    IJavaScriptProject jsProj = ... get your project object from somewhere ...
    //create an instance of the container from step 1.
    JsGlobalScopeContainerInitializer container = new LibInitializer();
    //create an includepath entry refering to the container         
    IIncludePathEntry entry = JavaScriptCore.newContainerEntry(container.getPath());
    
    IIncludePathEntry[] ipaths = jsProj.getRawIncludepath();    
    IIncludePathEntry[] newpaths = new IIncludePathEntry[ipaths.length +1];
    
    System.arraycopy(ipaths, 0, newpaths, 0, ipaths.length);
    //add the new entry
    newPaths[ipaths.length] = enty;
    // set the new includepath to the project
    jsProj.setRawIncludepath(newpaths, null);
    

    If you’re lucky now you’ll have a library entry in your JavaScript Resources containing all JavaScript objects and classes which are contained in the library folder you added with the ContainerIntitializer. And all this objects and classes will be available in the code completion suggestions.

    Finally a library!

    I hope that prevents someone else from spending hours of frustration on a topic that really could be simpler than it is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed an Eclipse plugin project. Now I need to convert it to
I have an Eclipse plugin project that has several file resources that I would
I have the following setup: eclipse a standard Java project (A) an eclipse plugin
I have an Eclipse plugin project, and it depends on other projects that I
I have created an eclipse plugin project and a corresponding fragment project which I
I have a eclipse plugin code to manipulate a class (smcho.Hello) in a project/workspace.
I have Eclipse with m2 plugin and want to make new project with Spring.
I have an Android Maven project using maven-eclipse-plugin and android-maven-plugin. Since it grabs the
I have an eclipse plugin project which uses some swt objects, eg - import
I have written a Eclipse plugin project and successful export the .jar files. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.