4 Replies Latest reply on Jul 19, 2017 4:08 PM by jamesm RSS
    wposner-2 Apprentice

    Custom Extension with conflicting TWX Jar

    I've written my own version of a CSV parser.  My version does not require a datashape to parse the CSV and it fixes the issue of requiring and EOL character after the last row/column. 

     

    I'm using a newer version of a library that ships with TWX.  Aside from renaming the jar file in the TWX folder so that my newer library jar doesn't conflict, what is the official method for installing an extension that makes use of a newer open sourced library?  The library in question is not included in the extension SDK so there is no way to reference it from within Eclipse without explicitly including the library as a TWX jar. 

     

    Also, I've decompiled the CSVParser currently available on the marketplace to find out if it was using the older library, and it does not.  So simply uninstalling the PTC CSVParser extension will not solve the issue.

     

    Once I've gotten this jar issue resolved, I'd like to submit my parser to the marketplace.

      • Re: Custom Extension with conflicting TWX Jar
        amarthouna Apprentice

        In your eclipse Project create a folder

        /lib

        Then add the jar file(a) inside the lid directory like

        /lib

            /myjar1.jar

            /myjar2.jar .... etc.

        For each jar file you add an entry in the metadata.xml like:

        ...
        <JarResources>
             <FileResource type="JAR" file="myjar1.jar" description="myjar1.jar description" />
             <FileResource type="JAR" file="myjar2.jar" description="myjar2.jar description" />
        </JarResources>
        ...
        

        If you are using Eclipse ThingWorx Extension Development Plugin then New Jar action will automatically update the metadata.xml for you.

          • Re: Custom Extension with conflicting TWX Jar
            wposner-2 Apprentice

            This is how you add an external jar to an extension project.  It does not answer the question on how you deal with a conflicting jar scenario. 

             

            In the Thingworx Web-Inf folder there are two subfolders--lib and extensions.  When you install an extension, the zip contents are extracted to the extension folder.  However, if there is a library already used by thingworx, it will be found in the lib folder.  You will NOT be able to install your extension if you use a jar library that is newer than one found in that lib folder.  In my case, I'm using opencsv-3.8.jar and Thingwrox is using opencsv-2.3.jar.  The only way I've been able to get my extension to install is to rename opencsv-2.3.jar to .bak and restart tomcat. 

             

            I need to know  how to use my newer version of the jar file without having to disable the jar file that was included with thingworx.

          • Re: Custom Extension with conflicting TWX Jar
            rpallares Explorer

            Great question, how to resolve jar conflicts into extensions?

            • Re: Custom Extension with conflicting TWX Jar
              jamesm Creator

              Remove the conflicting jar from your metadata file -- it shouldn't be necessary if there is a conflicting jar on the JVM.

               

              That said, there is an existing extension on the marketplace with this functionality: ThingWorx IoT Marketplace

               

               

              Edit: Just noticed you are using a newer version of the library -- there is no way to remove that via an extension; if two extensions are using the same library only the first one installed will work. This has to do with how tomcat loads libraries into the JVM, there is no way to unload a library at runtime, tomcat has to be shut down and the library must be removed from the classpath (as you suggested you have done).

               

              Parsley shouldn't have this issue, however -- it doesn't rely on the open csv library -- and also resolved the EOL problem and will parse CSV files without a data shape.