Quick note, I went through every single other question through here and nothing seems to work.
So, here is my issue. All I want to do is create a windows batch script that will be used to execute my selenium project on Jenkins. Sounds simple right ? Its probably is, but I am missing something...
Here is my project https://github.com/Daviditooe/Nomad
First command I tried:
javac src/nomad/execute/Execute.java
Execute.java:9: error: package nomad.sites does not exist import nomad.sites.MmaShare;
It also couldnt find any of the jars, so I add all of them
Then I tried:
javac -cp Jars\* src\nomad\execute\Execute.java
This fixed the jars issue but the package not found still exists
So then I tried compiling every single package at the same time
javac -cp Jars\* src\nomad\execute\*.java src\nomad\actions\*.java src\nomad\baseactions\*.java src\nomad\browsers\Chrome.java src\nomad\directory\*.java src\nomad\scripts\*.java src\nomad\sites\*.java src\nomad\urltools\*.java
So, now its not crashing, then I tried compiling...
java src\nomad\execute\Execute
And its giving me Could not find or load main class
So That last thing I tried was compile all of them at the same time.
java src\nomad\actions\MmaShareActions src\nomad\baseactions\BaseActions src\nomad\browsers\Chrome src\nomad\directory\Directory src\nomad\execute\Execute src\nomad\scripts\Vpn src\nomad\sites\MmaShare src\nomad\urltools\UrlTools
Still no luck... anything thoughts would be appreciated.
Again: You must go into the src folder before you execute javac and java!
I can compile and execute it on my Linux Laptop:
stefan#stefanpc:/hdd/stefan/Downloads/Nomad-master/src$ javac -cp '../Jars/*' nomad/execute/*.java nomad/actions/*.java nomad/baseactions/*.java nomad/browsers/Chrome.java nomad/directory/*.java nomad/scripts/*.java nomad/sites/*.java nomad/urltools/*.java
Note: nomad/baseactions/BaseActions.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
stefan#stefanpc:/hdd/stefan/Downloads/Nomad-master/src$ java -cp '../Jars/*:.' nomad.execute.Execute
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /hdd/stefan/Downloads/Nomad-master/src/C:\Users\Davidito\Desktop\AutoLinks\Jars\chromedriver.exe
Of course my Linux machine does not have the chromedriver.exe installed.
Under Windows, you must use "\" instead of "/" and you must use ";" instead of ":". Note that you must add the current folder "." to the class path when you execute the program. Otherwise java would only search in the Jars folder.
Related
I've never had issues with compiling with javac and running with java before, but here we are.
The program, MainApp.java, depends on a jar file and a few other programs, so I ran the following (which ran without issue):
javac -cp gson.jar *.java
However, when it comes time to run it, I can't seem to get it to work. I've tried:
java -cp gson.jar MainApp.java
but it complains that it can't find the other java files.
I then tried listing the file it said it was missing:
java -cp gson.jar RepositoryData.java MainApp.java
but it gave the same error.
I then tried listing all the dependencies:
java -cp gson.jar Comment.java Issue.java Owner.java Repository.java RepositoryData.java MainApp.java
but it complains that it can't find a main function in the Comment.java file - this leads me to think I'm going about this the wrong way, and I probably shouldn't be directly referencing dependencies in the java call.
I also know that the program does work, as I've compiled it using an editor without issue, but I'm required to do this via the command line for a class.
How should I be properly calling it?
I have a program that I run from Eclipse successfully.
However, when I want to run it from terminal, I encounter the famous error:
"java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver"
on this line:
Class drvClass = Class.forName("oracle.jdbc.driver.OracleDriver");
PS:
I have the following in CLASSPATH:
/oracle/jdbc/lib/ojdbc6.jar
Also note that I compile it successfully (javac Test2.java). Then when I run it (java Test2), I get the following error:
Error: Could not find or load main class Test2
So I run:
java -classpath ~/Desktop/JDBC2/src Test2
It runs, but I get the above "ClassNotFoundException" though.
I found this question tricky: the reason is related to semicolon after jar file address.
At first I changed the directory of MySample.java to another directory (you can don't do that) like C:\
then I removed package address from the source code, at the end I run this command in cmd
java -cp path_to_oracle_driver.jar; MySample
P.S. If you want run it from terminal you have to remove package PackageAddress from the source code and compile it again.
As #yngwietiger mentioned above in the comments, using -classpath parameter when running the .class file, overrides the original CLASSPATH and the predefined ojdbc6.jar file. So we need to mention both when running:
java -classpath ~/Desktop/JDBC2/src:/oracle/jdbc/lib/ojdbc6.jar Test2
Or, as a better solution, we can add the current path to CLASSPATH (note the colon and dot at the end):
export CLASSPATH=$CLASSPATH:.
And, in order to run, we just need to type:
Java Test2
I've a java script who's running by several user and working very well.
Today, I asked another user to try the script on his desktop and he's getting a ClassNotFoundException... despite the script is perfectly the same as mine (and jar locations is also the same)
Here's the command tu launch the JAR :
java -cp .;customname.jar;libs/* my.package.MyMainClass
And I also tried to add every jar in the libs folder separately :
java -cp .;customname.jar;libs/lib.jar;libs/lib2.jar;libs/lib3.jar my.package.MyMainClass
And here's the error message the user is getting :
Error: Could not find or load main class ch.vaudoise.hp.services.listener.AutoSysReorder
I checked the JAVA configuration and try to set him the same java version on "Path" environment variable. Same error.
As there's 6 user who can run the script and only one who's getting an error I'm sure it's a configuration issue. But what ? Classpath seems to be OK...
Many thanks for any help..
First things first: You must start by finding where is the conflicting class. If you don't know it, you may find it in two alternative ways:
Programatically: Code this class and execute it with the same classpath (on an environment that does not suffer the problem):
public static void main(String[] args)
{
System.out.println(ch.vaudoise.hp.services.listener.AutoSysReorder.class. getResource("/ch/vaudoise/hp/services/listener/AutoSysReorder.class"));
}
Manually, one by one: Open a command shell and execute:
javap -cp . ch.vaudoise.hp.services.listener.AutoSysReorder
javap -cp customname.jar ch.vaudoise.hp.services.listener.AutoSysReorder
javap -cp libs/lib.jar ch.vaudoise.hp.services.listener.AutoSysReorder
javap -cp libs/lib2.jar ch.vaudoise.hp.services.listener.AutoSysReorder
...
Try one by one every entry in the classpath until the class is found.
Once found the location of the class, open a shell in the conflicting PC and make sure that path is accessible:
dir lib\conflicting-library-or-directory
Also, repeat the javap test:
javap -cp conflicting-library-or-directory ch.vaudoise.hp.services.listener.AutoSysReorder
After this tests, you should have more clues to find the cause of the problem.
Take a look at ClassNotFoundException despite class in the classpath
You are also including meta character (*) in your classpath.
Try without that as suggested in the link.
Also some times copy pasting to command line , may get some characters copied differently.
I cannot add comment as of now : So , editing this answer.
| Java path is not an issue.
Try the following step by step :
- find which jar the class that is being not found is in .
- include only that jar as cp.
- include only that class and try
java -jar that.jar
Also try this once
java -cp "*;"
If you still got issue , probably the jar does not contain the class (You can open jar and check).
And you say script - is this single command which is failing or is it part of script ?. Using java -jar -cp , usually ignores cp.
I am pretty new to this but I seem to have a problem for a day now, and I can't get around it. Have looked over the other similar post but nothing worked. I just got the basic tutorial, made my Java file.
Used the javac HelloWorldApp.java command and got the class file.
But every time I try to run the java -cp . HelloWorldApp command, I get the Error: Could not find or load main class HelloWorldApp error. Pretty sure I am doing something wrong, just don't know what. I am on a Windows 7 machine with jdk1.8.0_31.
You can simply run your .class file with java filename command, provide you are running it from the src directory
Your current working directory may not be in your classpath, before running java class issue this command to include PWD into your classpath :
set CLASSPATH=%CLASSPATH%;.
java yourAppName
I had a fully functional Java program that I am now trying to put into a package instead of having it in the default package. All of the .java files are in the mymap package, and I am trying to run black box tests in my MyMapTest.java file. The problem is that I don't know how to properly run this in the command line now that I have it in a package. I got stuck trying to google for answers.
I can get it to compile:
javac -cp "../junit.jar" *.java;
But when I try to run it as I previously had...
java -cp .:../junit.jar org.junit.runner.JUnitCore MyMapTest
I get the error java.lang.NoClassDefFoundError: mymap/MyMap for all of my tests. I guess the issue is that somehow I am not properly including mymap, perhaps in the classpath?
Similarly, I also have white box tests in MyMapWhiteBoxTest.java, where this file is also in the mymap package. I cannot figure out how to properly run these tests either. Trying to run it the same way, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: MyMapWhiteBoxTest (wrong name: mymap/MyMapWhiteBoxTest)
For both cases, I have tried mymap/FILE or somehow also including the package in the classpath, but I'm definitely missing something.
If the main() is present in MyMapTest class then you can try the below command :
java -cp .:../junit.jar org.junit.runner.JUnitCore myMap.MyMapTest
After compilation: (javac -cp "../junit.jar" *.java;) what do you have in your current dir? You should have the file ./myMap/MyMapTest.class.