0

Have a java program jar with all the required dependable resource jars exploded and is working fine using below command.

java -cp path/to/MyProgram.jar com.......myMainFile

Now trying to put all the dependency jars inside the lib folder inside the same jar(MyProgram.jar) using maven and I see the lib folder and all the dependencies inside the jar i.e

MyProgram.jar/lib/all dependencies jars

Now not sure how to run my program and need help with the same. When tried to run same program using below getting error as No Class Found (i.e dependable jar class file) . Not creating meta-inf file as I have multiple main class files in my jar and want to execute them individually.

opai
  • 253
  • 1
  • 5
  • 14
  • Do you see the class you’re trying to run (com/…/myMainFile.class) in MyProgram.jar? – VGR Jan 12 '20 at 22:21
  • yes, it's running the my program and when trying to execute the logger statement inside the program getting error that it cannot the logger class which is in the dependent jar which is in lib folder inside the MyProgram.jar – opai Jan 12 '20 at 23:10
  • Are you placing other .jar files inside your program’s .jar file? Java’s classpath doesn’t work that way. It’s a search path, much like any shell’s `PATH` variable. – VGR Jan 12 '20 at 23:27
  • so, all dependable jars have to be placed manually to some folder on unix server and refer them is it? – opai Jan 13 '20 at 00:03
  • They need to remain separate files, if that’s what you’re asking. Whether you’re running on Unix or Windows, you will need to refer to all the .jar files in the classpath, separated by the system path separator character. You can do `echo "$PATH"` on Unix or `set PATH` in Windows to see an example. – VGR Jan 13 '20 at 00:49
  • oh ok. I exploded the dependable jars when creating the MyProgram.jar earlier using Maven. It works but, not advisable to do it I guess. I'll do as you suggested copy all the dependable jars manually to a folder on unix server and refer them in the shell script classpath and export the path. Thank you so much for your response. I really appreciate. – opai Jan 13 '20 at 01:46
  • Have one more question we are trying to use Maven now. The right way is to copy the dependencies from m2 to server / local lib path instead of manually copying it correct?? – opai Jan 13 '20 at 14:47
  • I’m not very knowledgeable in Maven. I don’t know which goals are available for copying files. – VGR Jan 13 '20 at 14:55
  • Thank you again for your help. ok my question is do we need to copy dependencies or directly use from m2 directory. replay if you know – opai Jan 13 '20 at 15:59
  • It doesn’t matter, as long as each .jar file is on the same machine as the program and its full path is in the classpath. – VGR Jan 13 '20 at 16:04
  • Got it. Thanks, it's clear to me now. – opai Jan 13 '20 at 16:45

0 Answers0