Unable to execute java program in jenkins? - java

I am trying to execute simple java class through jenkins and i have followed below post but no results,please help how to execute complete java program in jenkins.
How to compile and run a simple java file in jenkins on Windows
Always getting error as
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Run Java Class
[Run Java Class] $ cmd /c call C:\Windows\TEMP\hudson7739288570136427109.bat
C:\Program Files (x86)\Jenkins\workspace\Run Java Class>javac "E:\Java_Tutorials\JavaPractices\src\com\practice\javsSuperCars.java"
javac: file not found: E:\Java_Tutorials\JavaPractices\src\com\practice\javsSuperCars.java
Usage: javac <options> <source files>
use -help for a list of possible options
C:\Program Files (x86)\Jenkins\workspace\Run Java Class>java SuperCars
Error: Could not find or load main class SuperCars
C:\Program Files (x86)\Jenkins\workspace\Run Java Class>exit 1
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

The post that you referred was a sample example where the Java class that was executed was on the Jenkins Workspace folder directly, but your application is different as it is with a project folder structure.
Jenkins doesn't identify your Main class without you adding it to the CLASSPATH implicitly. Here the necessity of setting the CLASSPATH is more important.
In the Execute Windows batch Command section, you need to traverse to your Main class and then you need to issue the command to compile the same.
Hope this helps!

Related

Failed to run java in remote command line with external jar file

I want to run my Java code in remote server with external jar file. I referred to this tutorial and run IntelliJ IDE to generate a jar file of my whole project. Now I can run the following code in local terminal successfully.
javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java
java -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try
The code will run successfully. However, when I try the same thing in server. The compile process can be finished without any errors or warnings.
javac -cp /Users/natsuapo/out/artifacts/main_jar/main.jar: new_server_try.java
I have checked that the class file new_server_try.class is generated in the directory.
However the second step will return error as Could not find or load main class new_server_try and I am not sure why this happens.
on the second command try giving the full package name .. like shown below
java -cp "/Users/natsuapo/out/artifacts/main_jar/main.jar:lib/*" my.package.MainClass
also with operating system the command differs, check below
Windows
java -cp "Test.jar;lib/*" my.package.MainClass
Unix
java -cp "Test.jar:lib/*" my.package.MainClass

Why exec-maven-plugin fails while java console command works?

This problem has arisen while working with the Java Chromium Embedded Framework (JCEF).
The JCEF uses a native SO library (libcef.so) and a SO library for the JNI bindings (libjcef.so). I believe the embedded Chromium looks for a file named icudtl.dat next to it, i.e. in the same directory that the libraries reside.
For the following explanation, asume that all those required files are in the same directory, named jcef_libs.
I wrote a test application using JCEF. After compiling, if I execute it with the java command, i.e.
$ export LD_LIBRARY_PATH=/path/to/jcef_libs
$ java -cp src/main/java:/path/to/maven/repo/jcef.jar:/path/to/maven/repo/jogl-all/2.2.4/*:/path/to/maven/repo/gluegen-rt/2.2.4/* tests.simple.MainFrame
it works flawlessly.
On the other hand, using the exec-maven-plugin raises a fatal error, due to not finding the named icudtl.dat file. The POM file is configured to use exactly the same artifacts as the java command does.
$ mvn exec:java -Dexec.mainClass="tests.simple.MainFrame"
[1201/123038:FATAL:content_main_runner.cc(721)] Check failed: base::i18n::InitializeICU().
I have tested the java command with the icudtl.dat file removed from the jcef_libs directory, experiencing the same error, i.e. the error raises only when the icudtl.dat is not found.
Any help will be appreciated.
UPDATE
I have been tracing what maven does under the hood. The failing mvn command above executes this internally:
java -classpath /usr/share/maven2/boot/classworlds.jar -Dclassworlds.conf=/usr/share/maven2/bin/m2.conf -Dmaven.home=/usr/share/maven2 org.codehaus.classworlds.Launcher "exec:java" "-Dexec.mainClass=tests.simple.MainFrame"
I.e. it executes my test application through a launcher. I don't know where this launcher is going to execute my application but, again, I need the icudtl.dat in that directory.
Any idea how could I workaround this?

How to compile and run HelloWorld.java example from Sphinx4 without and IDE in Linux?

I have been testing the examples (HelloWorld.java) from Sphinx4 with Eclipse, but I would like to compile and run them from the command line.
The application needs 5 .jars to be able to run, I have read that in order to compile a java class with multiple .jars I need to execute the following command (as an example I will show short names):
javac -cp one.jar:two.jar:three.jar:four.jar:five.jar HelloWorld.java
The console does not throw any error messages:
parias001#parias001-pc:~/Projects/citadel_voices/sphinx_test > javac -cp jsapi.jar:sphinx4.jar:TIDIGITS_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar:WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz.jar:WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar HelloWorld.java
parias001#parias001-pc:~/Projects/citadel_voices/sphinx_test >
I think that the compilation succeeded. Now I would like to run the application, I read that in order to do this, I have to execute the command as follows (Using short name example as before):
java -cp one.jar:two.jar:three.jar:four.jar:five.jar HelloWorld
This is the message that the console throws:
parias001#parias001-pc:~/Projects/citadel_voices/sphinx_test > java -cp jsapi.jar:sphinx4.jar:TIDIGITS_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar:WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz.jar:WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar HelloWorld
Error: Could not find or load main class HelloWorld
I don't know what is going on here, I should also say that I do not have a lot of experience using external .jars.
The names of the .jars are:
jsapi.jar
sphinx4.jar
TIDIGITS_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar
WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz.jar
WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar
I appreciate any help you can give me.
You have to include current directory in classpath:
java -cp .:one.jar:two.jar:three.jar:four.jar:five.jar HelloWorld
Note the leading .:
From this reference:
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

Running a JAVA project with external jars folder

I'm trying to execute my JAVA app on a Linux OS where the necessary jars are located in a different folder. How can I execute my project using the external jars?
project location:
$ pwd
/root/MyApp/bin
$ ls
Deletion.class
jars location:
/opt/jars/*.jar
My failed execution:
$ java Deletion
... NoClassDefFoundError ...
$ java -cp "/opt/jars/*.jar" Deletion
Error: Could not find or load main class Deletion
When setting the class path with -cp ..., you have to also specify the current working directory (as this is not part anymore):
java -cp ".:/opt/jars/*.jar" Deletion
java -cp "location of jar file:." Deletion

How to run ZooInspector from Windows

Here's what I did:
Downloaded Apache ZooKeeper 3.4.6 (.tar file), extracted to C:\cygwin\home\user\zookeeper-3.4.6\
Ran ant at the root of the ZooKeeper folder (C:\cygwin\home\user\zookeeper-3.4.6)
Navigated to C:\cygwin\home\user\zookeeper-3.4.6\contrib\ZooInspector\
Ran ant, and I get the following error:
Output:
Buildfile: C:\cygwin\home\Jean\zookeeper-3.4.6\contrib\ZooInspector\build.xml
BUILD FAILED
C:\cygwin\home\user\zookeeper-3.4.6\contrib\ZooInspector\build.xml:19: Cannot find C:\cygwin\home\user\zookeeper-3.4.6\contrib\build-contrib.xml imported from C:\cygwin\home\user\zookeeper-3.4.6\contrib\ZooInspector\build.xml
Total time: 0 seconds
This leaves me with no .cmd or .sh file to execute. How come the build-contrib.xml file isn't there?
Also, I noticed that there seems to be an already-compiled ZooInspector JAR file: zookeeper-3.4.6-ZooInspector.jar. However, attempting to run it with the following command yields failure too:
$ java -cp zookeeper-3.4.6-ZooInspector.jar:lib/* org.apache.zookeeper.inspector.ZooInspector
Error: Could not find or load main class org.apache.zookeeper.inspector.ZooInspector
This is a bit frustrating -- setting up the ZooKeeper server was straightforward but for some reason I just can't figure out how to run this standalone GUI. What am I missing?
For windows:
#echo off
set cp="./*;./lib/*;../../*;../../lib/*"
java -cp %cp% org.apache.zookeeper.inspector.ZooInspector
ZooInspector 3.4.6 (that's bundled with ZooKeeper 3.4.6) doesn't seem to be able to connect to a running ZooKeeper instance on Windows.
Better use zkui:
https://github.com/echoma/zkui/wiki/Download
zooInspector just need 3 libraries and 1 jar to load the main class.
the mainclass lives zookeeper-3.3.0-ZooInspector.jar and it needs jtoaster-1.0.4.jar, zookeeper-3.3.0.jar and finally log4j-1.2.15.jar
After download the tar.gz file from apache servers, you must untar and build with ant. finally copy the zookeeper-3.3.0.jar and log4j-1.2.15.jar to contrib/ZooInspector/lib/. Finally cd to contrib/ZooInspector and launch this command
java -jar zookeeper-3.3.0-ZooInspector.jar -cp lib/*
I met the same issue today, and created a pre-compiled version, which should work on Windows as well. You can find details here:
https://www.admon.org/scripts/zooinspector-zookeeper-graphic-interface/

Categories