I'm having trouble using my testNG suite in the Jenkins of my company. Here is the set up :
-Jenkins is installed on a Linux machine so I have to create a .sh which launch my tests.
-I code my tests under Windows, on Eclipse in Java.
-I have to use relative path in my project.
-I use my file blex_test_v1.xml to launch my tests.
I did write a batch script, it works fine without problem :
I now try to "convert" it into a .sh so this is what I have for the moment :
The problem is that I always get this error :
"Error Could not find or load main class org.testng.TestNG"
There is about 6 or 7 posts on StackOverflow about this problem, I've read all of them, trying to change my code, rewrite it, I even uninstall all .jar files and reinstall them in my lib ... Can't see where is the problem coming from.
It can't be from the plug-in, jar files, main Class (I don't have any), my different paths or org.testng.TestNG because my .bat is working with the same meta or maybe it is different in bash script ?
For the moment I don't use Jenkins, I first try to make a runnable script and I'm reeeeally stuck here ... What am I doing wrong ?
Thanks !
PS : Here is the architecture of my project (admire my artist skills) :
EDIT: I don't use maven nor ant nor gradle, just Java in eclipse with testNG and reportNG plug-in
EDIT 2 : I used this answer to make my bash this guy says it is working fine, but it is not for me, even if I code it with ./ (still the same error as above):
java -cp ./blex_test_v1/lib/*:./blex_test_v1/bin org.testng.TestNG ./blex_test_v1/blex_test_v1.xml
EDIT 3 : I found another typo but still got the same error :
export CLASSPATH=./blex_test_v1/lib/*:./blex_test_v1/bin;
java org.testng.TestNG blex_test_v1/blex_test_v1.xml
Note : the * makes the code look like it is commented but it is not
After a couple of days I finally solved the problem by making a main class in my Java project calling the XML file, then create an executable jar of my project and in the end create a bash script calling this jar.
The code of my .sh is here (quite simple) :
java -jar Exec.jar
Related
I've a Java backend application (Traccar). I compile and start the application selecting the following configuration:
The I click on run to execute the program, and everything works. My question is: how can I do the same from command line? All the settings in this image, how are they translatable to some commands?
If I have to do run the program from command line, how can I select the main class (org.traccar.Main), the module (-cp tracker-server.main) and so on?
Thank you everybody.
You should compile the JAR file first and then run it using something like this:
java -jar tracker-server.jar conf/traccar.xml
I'm remoted into a Linux machine that I don't own from my Windows machine. I've got 2 java files:
DBConnect.java
Main.java
I compile and run them fine on my machine and in my IDE (I'm using NetBeans). When I copy them to the remote Linux machine, the place they're located is:
/home/NETID/myname/430
I compile them using:
javac *.java
They compile successfully, which creates two new files:
DBConnect.class
Main.class
I then attempt to run Main.class. With each of the following commands, I get the error "Error: Could not find or load main class Main"
java Main
java <pkg>.Main
java <pkg>/Main
In my case, in NetBeans, my project is called MyProject. In the directory structure on the left-hand side of the IDE window, there is MyProject. Under that is a file called Source Packages. In that file is another thing called pkgMyProject. When I expand that, I see my two java files.
Also, at the top of both Main.java and DBConnect.java, there is:
package pkgMyProject;
I've read some other questions here referring to this issue, but I'm having trouble understanding the answers. Also, many of the answers don't apply because I don't think I can set the classpath on the remote machine.
When I check my classpath in my terminal (when I'm remotely connected) using...
echo ${CLASSPATH}
...nothing is displayed.
How can I find my classpath, and how can I run these files?
I think you are missing the package folder. You need to create a directory in the Linux machine with the name pkgMyProject. Then, run javac pkgMyProject/*.java and run java -cp . pkgMyProject.Main after that.
Update: You can add the -cp to set the classpath to be used in the java command.
I've installed zookeeper v 3.4.9 on suse using the following package:
http://download.opensuse.org/repositories/home:/nicolasbock:/midokura/openSUSE_Leap_42.2/x86_64/zookeeper-3.4.9-1.1.x86_64.rpm
Starting the server works just fine an the various application that need to connect to it seem to be able to do so just fine, however I'm getting a strange error when I try to start the client:
zkCli.sh -server 127.0.0.1:2181
Error: Could not find or load main class org.apache.zookeeper.ZooKeeperMain
I've tried searching around the internet but the only answer I've come up with is setting the env variable $CLASSPATH. I tried looking what classpath is used internally by the serve starting script and set $CLASSPATH to that but with no results.
I'm running openjvm v 1.8.0_121
I encountered this problem today on Ubuntu 18.04. On zookeper official download page once one follows the given mirror link and chooses stable version, he can see 2 files available. In my case those were:
apache-zookeeper-3.5.5-bin.tar.gz
apache-zookeeper-3.5.5.tar.gz
I chose apache-zookeeper-3.5.5.tar.gz, observed the same problem. Tried to print CLASSPATH as #Jonathan suggested, it was printing different paths however, problem is that the archive file did not contain zookeper jars, probably it is expected that user packages to jar himself as I could find source code in that archive file.
Downloading larger apache-zookeeper-3.5.5-bin.tar.gz archive, extracting and running ./zkCli.sh went smooth as it had everything necessary, so whoever faces the same problem, try that and see if it does the trick for you.
Are you trying on Unix or Windows?
I dont think, you need "-server 127.0.0.1:2181"
Just run zkCli.sh or zkCli.cmd
That is a classpath problem. The zkCli.sh script is attempting to launch a java app where the main class is ZooKeeperMain. However, java cannot find the ZooKeeperMain class file because the classpath being passed to java does not contain a jar file that contains the ZooKeeperMain class.
Typically, the ZooKeeperMain.class file is contained in a jar file at something like $ZOOKEEPER_HOME/zookeeper-3.4.13.jar.
You might trying modifying the zkCli.sh script to print out the classpath just before the script attempts to launch ZooKeeperMain. The classpath should contain the jar that contains the ZooKeeperMain class.
On my Windows 10 machine, my classpath looks like this:
/c/Program Files (x86)/Zookeeper/bin/../build/classes:/c/Program Files (x86)/Zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/netty-3.10.6.Final.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/log4j-1.2.17.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/jline-0.9.94.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/c/Program Files (x86)/Zookeeper/bin/../zookeeper-3.4.12.jar:/c/Program Files (x86)/Zookeeper/bin/../conf:
I encountered a similar errors as yours when launching zkCli.sh from Git Bash for Windows on my Windows 10 machine. My issue was because of the way Git Bash was handling wildcards in the classpath. I initially had some *.jar entries in my classpath that I removed to get zkCli.sh to launch.
In CMD I compile project with including libraries
java -cp app.jar;libs/*;. com.app.Main
and it works, but I want create BATCH script, which do exactly the same. I create test.bat and put code like below:
#ECHO off
java -cp app.jar;libs/*;. com.app.Main
PAUSE
But when I run the test.bat the CMD was shown and there is information "Error: Could not find or load main class com.app.Main".
BATCH script is located at the same folder as app.jar and libs folder.
What is wrong with this batch script?
Probably the characters on the compile line are significant to the batch interpreter; try putting the classpath in double quotes.
After Java 6, Classpaths could be built by using wildcard characters.
You can create a directory named classpath and put your JARs inside it. Then you can create your .bat file like this:
#ECHO off
java -cp .;classpath/* com.app.Main
pause
You should have a structure like this:
com
`---app
`---Main.java
classpath
`---your-crital-code-1.0.jar
compile.bat
I see that a lot of people are asking this question on StackOverflow, so here is a little tip for you guys.
I usually avoid using the cd command, as it may create some hassle. In windows, you can Shift + Right Click to open a command window in a particular directory.
I always prefer relative paths over absolutes, so that I don't get into hassle of managing long paths.
Here is a little program that deals with this kind of problem. You can always refer to and contribute to it so that we can make good examples for Java beginners :)
I have the following package on Eclipse:
com.mortgageapp.projects.app
I'm not interested about the package format at the moment, it's just testing. But I'm wondering how to run the app from the terminal (Windows and Mac)?
It contains a Main.java file where it will begin so I have tried locating and entering the src folder. Then doing something like: javac com/mortgageapp/projects/app/Main.java (or: javac com/mortgageapp/projects/app/*.java).
Just wondering if this is current as when I then do: java com/mortgageapp/projects/app/Main I get a few errors.
Your compilation is probably okay, but to run it you need to specify the class name, not a filename:
java com.mortgageapp.projects.app.Main
That's assuming the current directory is in the classpath. If it's not, you may need:
java -cp . com.mortgageapp.projects.app.Main
I assume you are writing an RCP application.
Export the project as a RCP application (click the "export" link in your product configuration). You should get a runnable application file.
If you really want to run the application from the terminal, you need to use the main function in the EclipseStarter. But you don't want to go there unless you are doing something very special.