Include third party Jar files into project

I have a Java Jar lib i want to include in the project. It is not Vaadin Jar.
How and where do i put it?

1 Like

Problem solved.

  • In Studio, go to Project Properties > Edit > Advanced

  • Add compile dependency for “core” module and specify its coordinates, like “activemq:activemq-client:5.13.0”

  • After saving changes, Gradle will recompile the project and recreate IntelliJ files.

If you have a standalone JAR, you have to add a file-based repository to build.gradle manually, for example:

buildscript {

repositories {
maven {

}
flatDir { dirs ‘c:\work\lib’ }
}
After that, place your JAR into this directory and specify the dependency as described above. The coordinates must contain at least two parts: “mylibrary:myfile”, where “mylibrary” is an arbitrary group (it is ignored) and “myfile” - name of the JAR file (myfile.jar)
Remember that don’t use .jar in (“mylibrary:myfile”) in studio. Then it build like a charm.

Hi
When I want to use a 3rd party jar (say, barcode4j.jar) in my project, do I need to download the jar file and place it somewhere in my project or the system will download it based on my dependency definition like: “barcode4j:barcode4j:2.1” ? I have done this and can see the file in the library file list but it is not availalble to call for some reason.

You have to download the Jar file. place it some where on the harddrive ex: c:\proj\lib\barcode4j.jar

Then ref the path on drive in build.cradle like this under the bracket for maven:

buildscript {
    ext.cubaVersion = '6.1.2'
    repositories {
        maven {
            url 'https://repo.cuba-platform.com/content/groups/work'
            credentials {
                username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba')
                password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123')
            }
        }
        maven {
            url 'https://repo.cuba-platform.com/content/groups/premium'
            credentials {
                username(rootProject.hasProperty('premiumRepoUser') ? rootProject['premiumRepoUser'] : System.getenv('CUBA_PREMIUM_USER'))
                password(rootProject.hasProperty('premiumRepoPass') ? rootProject['premiumRepoPass'] : System.getenv('CUBA_PREMIUM_PASSWORD'))
            }
        }
        <b>flatDir { dirs 'c:\\proj\\lib' }</b>
    }
    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
    }
}

Now you can put it in to the Advanced tab in project settings like this:
mylib:barcode4j
Don’t use .jar extension. only jar name.
You must also include the jar in buildpath in Eclipse og IntelliJ.

Hi Kjell,
Thank you for the help. I have some progress but still have something to be fixed (i am using mac OS):

  1. created a folder: /Users/Mortoza/studio-projects/bin and saved the barcode4j.jar and some other files i see there. my project path is here: /Users/Mortoza/studio-projects/barcode
  2. Added those dependencies in IntelliJ: project structure >> modules >> app-web >>
  3. added the line in gradle as below:

ext.cubaVersion = '6.1.2'
    repositories {
        maven {
            url 'https://repo.cuba-platform.com/content/groups/work'
            credentials {
                username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba')
                password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123')
            }
        }
        maven {
            url 'https://repo.cuba-platform.com/content/groups/premium'
            credentials {
                username(rootProject.hasProperty('premiumRepoUser') ? rootProject['premiumRepoUser'] : System.getenv('CUBA_PREMIUM_USER'))
                password(rootProject.hasProperty('premiumRepoPass') ? rootProject['premiumRepoPass'] : System.getenv('CUBA_PREMIUM_PASSWORD'))
            }
        }
        //flatDir { dirs "\\Users\\Mortoza\\studio-projects\\lib" }
        //flatDir { dirs '/Users/Mortoza/studio-projects/lib' }  //for mac OS
        flatDir { dirs '\\Users\\Mortoza\\studio-projects\\lib' }  //for mac OS
    }
    dependencies {
  1. Added in Project >> Advanced : core model (compile): mylib:barcode4j:2.1
  2. Now I can use it in IntelliJ (library setting in IDE seems worked) but not in the studio. While I start the app-server, getting the following error indicates the studio is not finding this jar files.

Here is the error -


:app-web:compileJava/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:8: error: package org.apache.avalon.framework.configuration does not exist
import org.apache.avalon.framework.configuration.Configuration;
                                                ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:9: error: package org.apache.avalon.framework.configuration does not exist
import org.apache.avalon.framework.configuration.ConfigurationException;
                                                ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:10: error: package org.apache.avalon.framework.configuration does not exist
import org.apache.avalon.framework.configuration.DefaultConfiguration;
                                                ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:11: error: package org.krysalis.barcode4j does not exist
import org.krysalis.barcode4j.BarcodeException;
                             ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:12: error: package org.krysalis.barcode4j does not exist
import org.krysalis.barcode4j.BarcodeGenerator;
                             ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:13: error: package org.krysalis.barcode4j does not exist
import org.krysalis.barcode4j.BarcodeUtil;
                             ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:14: error: package org.krysalis.barcode4j.impl.datamatrix does not exist
import org.krysalis.barcode4j.impl.datamatrix.DataMatrix;
                                             ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:15: error: package org.krysalis.barcode4j.output.bitmap does not exist
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
                                           ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:34: error: package org.krysalis.barcode4j.impl.datamatrix does not exist
    private org.krysalis.barcode4j.impl.datamatrix.DataMatrix bean = new DataMatrix();
                                                  ^
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:36: error: cannot find symbol
    BarcodeUtil util = BarcodeUtil.getInstance();
    ^
  symbol:   class BarcodeUtil
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:37: error: cannot find symbol
    BarcodeGenerator gen;
    ^
  symbol:   class BarcodeGenerator
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:40: error: cannot find symbol
    public void generateBarCode()  throws ConfigurationException, BarcodeException, IOException {
                                          ^
  symbol:   class ConfigurationException
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:40: error: cannot find symbol
    public void generateBarCode()  throws ConfigurationException, BarcodeException, IOException {
                                                                  ^
  symbol:   class BarcodeException
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:54: error: cannot find symbol
    private static Configuration buildCfg(String type) {
                   ^
  symbol:   class Configuration
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:34: error: cannot find symbol
    private org.krysalis.barcode4j.impl.datamatrix.DataMatrix bean = new DataMatrix();
                                                                         ^
  symbol:   class DataMatrix
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:36: error: cannot find symbol
    BarcodeUtil util = BarcodeUtil.getInstance();
                       ^
  symbol:   variable BarcodeUtil
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:46: error: cannot find symbol
        BitmapCanvasProvider canvas = new BitmapCanvasProvider(
        ^
  symbol:   class BitmapCanvasProvider
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:46: error: cannot find symbol
        BitmapCanvasProvider canvas = new BitmapCanvasProvider(
                                          ^
  symbol:   class BitmapCanvasProvider
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:55: error: cannot find symbol
        DefaultConfiguration cfg = new DefaultConfiguration("barcode");
        ^
  symbol:   class DefaultConfiguration
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:55: error: cannot find symbol
        DefaultConfiguration cfg = new DefaultConfiguration("barcode");
                                       ^
  symbol:   class DefaultConfiguration
  location: class GoodIssueEdit
/Users/Mortoza/studio-projects/barcode/modules/web/src/com/company/barcode/web/goodissue/GoodIssueEdit.java:58: error: cannot find symbol
        DefaultConfiguration child = new DefaultConfiguration(type);
        ^

Did you include the jar file for org.apache.avalon.framework.configuration.Configuration?
I have made a tiny demo for use of plain barcode in the attached zip project called BarcodeDemo.
Here I have imported the barcode4j jar lib and avalon-framework-4.2.0.
You must change the path in build.gradle to fit your path.
Both:
barcode4j.jar and avalon-framework-4.2.0.jar but be in the same path.

Please change output folder to fit your needs. I dumped the image file to “c:\work\output.png”. See SERVICE in CUBA Studio.
The it should be a file named barcodedemo_BarcodeService.

I got it to run with no problem.

BarcodeDemo.zip (98.4K)

1 Like

Awesome :slight_smile: you’re so good. Thank you.

Now I 'll explore DataMatrix barcode generation, saving to database and use it in report. If you have something around and can share that is more than welcome.