Inside Jenkins, I already setup a build.xml to use Ant to compile the Java code and output as a jar.
I can run the compiled jar without problem in command line.
However, after letting Jenkins to run the same jar file, I met an error “[exec] Error: Could not find or load main class”.
I checked the classpath in these two situations (in command-line vs. in Jenkins) and got identical results.
This is so bizarre. My Jenkins is the latest long-term-support version and Java is 1.7.
Finally figured out the reason. I have a file that can be accessed by group members. However, Jenkins used its own account (cannot access that file needed for running the program). After granting access right to the Jenkins, my program (bash script) can run without any problem.