Home » Java » java – Build .jar with dependencies-Exceptionshub

java – Build .jar with dependencies-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I am trying to compile my java project into a .jar file. It contains many (50+) external libraries that I linked into a project subfolder called “lib”.
I am using vscode with java extension to code and it seems to recognize the libraries fine.

project architecture

Now, if I am trying to use the “build .jar” command from vscode, I get errors saying imported packages does not exist.
The default command used by vscode is the following:

rm -rf /mnt/data/work/CDYYY-Dev/star-utils/japyCCM/build-jar && mkdir /mnt/data/work/CDYYY-Dev/star-utils/japyCCM/build-jar && javac -d /mnt/data/work/CDYYY-Dev/star-utils/japyCCM/build-jar /mnt/data/work/CDYYY-Dev/star-utils/japyCCM/src/* && jar cvf /mnt/data/work/CDYYY-Dev/star-utils/japyCCM/build-jar/Run.jar /mnt/data/work/CDYYY-Dev/star-utils/japyCCM/build-jar *

/mnt/data/work/CDYYY-Dev/star-utils/japyCCM/src/Parser.java:6: error: package com.google.gson does not exist

There must be a way to tell the compiler to attach the libs I am using but I dont find any. I only find topics talking about Maven projects but mine is not a Maven project.

I tried to reach the support of vscode java extension but they tell me its not an extension problem and they won’t help me.
I am getting a bit confused with only answers referring to Maven projects whereas I just want to keep the project as simple as possible and attach my dependencies.

Thank you very much

How to&Answers: