0

This question has been asked before but I searched through almost all of them and still can't find an answer fitting to solve my problem.

So I created my java program and when I run it in IntelliJ all is OK. In File->Project Structure I have created a new jar with 'from modules with dependencies'. I set the manifest file in my src/main/java in the manifest file my main class is defined: 'Main-Class: telematics.GetTelematicsData' and I write the jar file to my desktop. I did build->build artifact and the jar is placed on my desktop. when I run the jar file from command line with following command

java -jar filepath.jar

It throws the error:

Error: Could not find or load main class telematics.GetTelematicsData

I took the jar file and unzipped it. When I looked into the unzipped folder in the structure there is a telematics folder with a file GetTelematicsData.class (which is indeed my main class).

Some people say in SO that it might be because of some dependencies in maven in the POM file which give the error, but I have no idea how to find the incorrect ones nor how to test this.

mrdeadsven
  • 744
  • 1
  • 9
  • 22

1 Answers1

1

If you are already using Maven, I see no reason for you to use Intellij to export a jar. I'd recommend using maven as it would be very helpful if you need to do an automated deployment in the future rather than the manual process of cutting a jar. Simply open your terminal or command prompt and change directory to your project folder and type.

mvn clean package 

You should see a jar created in the target directory.

project/target/your-java-appliation-1.0.jar

If you are using a release plugin check out here. There are other plugins as well and I encourage you to explore those. Here is a another StackOverflow link that talks about compiling a jar with all it's dependencies.

na-98
  • 909
  • 8
  • 16
  • thank you this solved the issue, any idea why it works when building with maven and not just with the artifact builder of intellij? – mrdeadsven Sep 03 '19 at 07:22
  • 1
    @mrdeadsven I think you have to configure intellij to include all the dependencies to path. I haven't looked much into it but that's my guess. – na-98 Sep 03 '19 at 20:53