0

I have a strange issue with jar file I'm building, and I was wondering if anyone could point me to any manual or KB article, that would explain it... Anyhow, my application is referencing external iText-2.0.8.jar that resides in the same directory as my output jar: OUT_DIR: - my.jar - iText-2.0.8.jar the main class in my.jar is com.company.Main and whenever I'm trying to run

java -cp "my.jar;iText-2.0.8.jar" com.company.Main

my app runs fine. But as soon as I'm trying to run:

java -jar my.jar

I'm getting NoClassDefFoundError for classes from iText-2.0.8.jar Here is the manifest of my.jar:

Manifest-Version: 1.0
Main-Class: com.company.Main
Class-Path: iText-2.0.8.jar

Name: rabbitmq-client
Specification-Title: AMQP
Specification-Version: 0.9.1
Specification-Vendor: AMQP Working Group (www.amqp.org)
Implementation-Title: RabbitMQ
Implementation-Version: 3.1.3
Implementation-Vendor: Rabbit Technologies Ltd. (www.rabbitmq.com)

Could that be related to iText jar being runnable as well (it has it's own main class)? On the other hand, NoClassDefFoundError clearly indicates classpath error...

1 Answers1

0

The -cp parameter setup classpath. The problem is that you have to include iText.jar in runtime dependencies. When you run without specifying classpath then you get NoClassDefFound error and it's totally normal behaviour. Probably you've something wrong according to manually creating manifest file. Better option is to make IntelliJ IDEA to generate it for you. To do this you have to:

  1. On the main menu, choose Build | Generate Ant Build.
  2. Ensure you've checked "Inline runtime classpath" checkbox
  3. OK
Jakub Kubrynski
  • 13,724
  • 6
  • 60
  • 85