1
  1. Do I need to have main class in one of entry point class?
  2. I tried with adding main class, but when i am trying to pass its saying main class could not load or not found.

Here is the command i used:

jar -xvf jarname.jar 
java -cp /path/filename.class $JOB_URL $USER $PASSWORD

path name is the filename where entry point and has main() method.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Rocky Hai
  • 353
  • 1
  • 5
  • 17

1 Answers1

1

1) Do I need to have main class in one of entry point class?

Yes. and passing parameters should not require to uncompress the jar archive: see "How do I pass parameters to a jar file at the time of execution?"

java -jar jarname.jar  param1 param2

But that require a MANIFEST file inside the jar which reference the main class.

Main-Class: MyPackage.MyClass

Or you can use -he 'jar e' option (if your jar has no Manifest.txt file):

If the entrypoint class name is in a package it may use a '.' (dot) character as the delimiter.
For example, if Main.class is in a package called foo the entry point can be specified in the following ways:

jar cfe Main.jar foo.Main foo/Main.class

In both cases, you wouldn't have to uncompress the jar.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @RockyHai Yes, as described in https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html. But you can also test your jar without assuming the presence of a `Manifest`, with `jar cfe` command, as mentioned in the last part of the answer. – VonC Jul 15 '17 at 20:04
  • currently I didnt add Manifest.mf so I can use jar cfe jarname.jar path.entryclass $param. – Rocky Hai Jul 15 '17 at 20:12
  • @RockyHai yes, that is the idea. If you don't have a `Manifest`, you would use `jar cfe jarname.jar path.entryclass path/entryclass.class $param` (don't forget the `.class` pathname in addition of the class name itself) – VonC Jul 15 '17 at 20:14
  • when I am passing parameters and building it through Jenkins, jenkins build is failing param:no such file or directory. Now main class issue resolved. Can you help me in this? – Rocky Hai Jul 15 '17 at 20:28
  • @RockyHai Yes, but it is best to ask a new question, with the exact Jenkins version (and java version, and OS version) used, along with the kind of job (freestyle? maven?) used, and the exact command used in the job configuration. – VonC Jul 15 '17 at 20:30
  • Thanks VonC, im passing as jar cfe jarname.jar path.entryclass path/entryclass.class $user_name $password $database. – Rocky Hai Jul 15 '17 at 20:37
  • I added $user_name and $password $database as parameters in Jenkins – Rocky Hai Jul 15 '17 at 20:38
  • @RockyHai That will aviod having to read comments: a brand new question allows you to lay out the details in the question section. Don't forget to mention the OS, Jenkins and Java version as well: that helps others to answer more precisely. – VonC Jul 15 '17 at 20:39
  • I am not allowed to ask another questions, its saying to wait for one more day to ask another question :( – Rocky Hai Jul 15 '17 at 20:42
  • @RockyHai I am sorry for that, I forgot about that limitation. – VonC Jul 15 '17 at 20:43
  • @RockyHai But I'll be there tomorrow, as I have been those past 2971 days (https://meta.stackexchange.com/q/122976/6309). More importantly, other specialists will be there too. – VonC Jul 15 '17 at 20:44
  • I have posted another question. Could you please have a look of it. – Rocky Hai Aug 04 '17 at 21:08