Java don't run the main file (classpath) - java

Hello guys i'm new with java and i'm starting to work with packages etc, i have a problem when i try to run my main file located at
C:\Users\Robert\Desktop\Java\latebd\Test.Java
When i run
java -cp C:\Users\Robert\Desktop\Java\latebd\latebd.Test
instead of having the code running i get this (it's in italian bu basically it's telling all the options when i use java -
Why do i get that?

you need to compile it e.g. javac C:\Users\Robert\Desktop\Java\latebd\*
provide the path where it's already compiled as a classpath, and to run it use java -cp "C:\Users\Robert\Desktop\Java\latebd\*" latebd.Test

Try java -cp "C:\Users\Robert\Desktop\Java\latebd\latebd.Test"

Related

Running a java program through command line

I am running a Java program with the following command:
java -cp .:./* com.bot.fix.botclient
All the jar files are in the same directory. It works FINE! But what if I want to run it from a different folder?
The full location of the java program is: FIX/fixprog/src/com/fix/botclient
But if I try to run:
java -cp FIX/fixprog/src/* FIX/fixprog/src/com.bot.fix.botclient
I get:
Error: Could not find or load main class FIX.fixprog.src.com.bot.fix.botclient
What am I doing wrong? How can I run the same Java program but not in the same directory?
If you have only jar files try:
java -cp FIX/fixprog/src/* com.bot.fix.botclient
If you have also classes you should try:
java -cp FIX/fixprog/src/*:FIX/fixprog/src/ com.bot.fix.botclient
If both did not work perhaps you shoud use absolut path with disk unit if you are using windows.
Try if below works. You don't need to specify path when giving the fully qualified name of your java class that you are trying to execute. The "cp" part takes care of it.
java -cp FIX/fixprog/src com.bot.fix.botclient

How to run java code from shell script on linux

I want to set a cron job for my java code and I have tried this from project directory
java -classpath .:/home/project/lib/* pkg_name.my_code
and it works fine, however I dont know how to run it from any other directory[like in script]
I have tried to add diroctry (having compiled classes) in classpath like this
java -classpath .:/home/project/lib/*;/home/project/pkg_name/* pkg_name.my_code
also tried
java -classpath ".:/home/project/lib/*;/home/project/pkg_name/*" pkg_name.my_code
but it gives error:
**Error: Could not find or load main class pkg_name.my_code
**
can any please help me ?
If you want to run your project from another directory, then you need to include your project in classpath. So you can do this
java -classpath ".:/home/project/lib/*:/home/project" pkg_name.my_code
For example :
java -classpath ".:/home/test/runjavafromanotherdirectory/lib/*:./runjavafromanotherdirectory" com.test.Main
One of your mistake is you are using ; instead of :.

Run A Java Program That Calls On An External Jar

I'm trying to run a Java program that calls on the C:\Users\Brandon\Downloads\commons-io-2.4 folder. It compiled fine with this code javac -cp "C:\Users\Brandon\Downloads\commons-io-2.4\*" Login.java but when I tried to run it with this code
java -cp C:\Users\Brandon\Downloads\commons-io-2.4\* Login it gave me thiserror: Could not find or load main class Login.class How do I fix this?
P.S. The program calls on the FileUtils.
You need to add the current location as part of classpath.
java -cp .;C:\Users\Brandon\Downloads\commons-io-2.4\* Login
symbol .(dot) is the current path, separated by comma
Try this: java -cp C:\Users\Brandon\Downloads\commons-io-2.4\*;. Login
You have to add the current directory to the class path
If that doesn't work try java -cp C:\Users\Brandon\Downloads\commons-io-2.4\* -cp . Login

Cannot find class in classpath

I've been reading up on this error but am now confused. I'm trying to run my java test file from the win7 cmd line but am getting that dreaded error cannot find class in classpath.
The script runs fine as a testNG file inside the Eclipse IDE but not from the cmd line.
My classpath dump:
C:\lib\selenium-java-2.37.0.jar;
C:\lib\selenium-server-standalone-2.37.0.jar;
C:\EclipseIDE\ProteinBar\bin;
C:\EclipseIDE\ProteinBar\src\com\proteinbar\staging;
C:\TestNG;
My cmd line test string:
java -cp C:\lib\*;C:\EclipseIDE\ProteinBar\bin org.testng.TestNG DeleteBillingAddress.xml
Thanks for any help...
it doesn't appear that the testng jars are on your classpath. I'm guessing they live under c:/testng so you'll want to add something to your -cp reflecting that.
You need to specify the jars individually, e.g.,
java -cp C:\lib\selenium-java-2.37.0.jar;C:\lib\selenium-server-standalone-2.37.0.jar;...

Want to call C++ code from Java code using JavaCPP?

I want to call c++ code from java code by using JavaCPP.
I am trying to run there own example of LegacyLibrary on http://code.google.com/p/javacpp/
when I try to compile code with following command mentioned at site only
javac -cp javacpp.jar:. LegacyLibrary.java
I get the following exception on console
I don't under where I am wrong. I am specifying the path of jar which contains com.google.javacpp.* classes.
You're on Windows, so you should be using ;, not : as a separator for the elements in your classpath.
Try with:
javac -classpath javacpp.jar;. ....
(Assuming that jar file is indeed in your current directory.)

Categories