cannot run java file in command line that created by eclipse - java

If I create Java file by touch command in command line, edit it using nano, compile it by javac, and then run it, all works well.
But if I use eclipse to build the project, and create file in eclipse. I can compile it using javac, but cannot run it in the command line.
it shows
Error: Could not find or load main class
why this happen? is anything wrong?

sounds like all about right path in which you trying to run your class.
did you use packages? did you run it from bin|target|build dir?
please provide commands and paths from which you trying to execute it

Related

Cannot compile Apache Netbeans project using Ant from command line

I was trying to set up compiling a Netbeans project from the command line. The project uses Ant as a build system, so I found this and followed it. The program compiles fine, however, when trying to run the program using java -jar file.jar it terminates, saying no main manifest attribute.
Furthermore, I would also like to know if there is a way to run the ant command for a specific file, like one would in netbeans when right-clicking and selecting Run file, as when running ant jar there is no opportunity to select a file.

Running jar file in command prompt. Java can't find libraries in classpath

EDIT: OK, I think I was being silly. What I really wanted to do was a runnable JAR. I did and now it works.
So I'm trying to run a little program that interacts with some webpages. The program works fine when I launch it from Eclipse but when I export it to a jar file and try to run it from the command prompt I get this error message:
What am I missing here?
I'm assuming in Eclipse you've added the appropriate libraries to your build path. When you run your program through eclipse, it automatically creates a java command including all your libraries in the classpath.
You need to do the same thing
java -cp /path/to/libs -jar muzictest.jar

How to copy my Java Eclipse project to desktop, and then run with the command line?

I have built a java program using Eclipse. Now my teacher wants all separate java files in one folder, and then the teacher will run my program through command line. I've tried copying the java files over to my desktop and running through command line, I get errors.
My program also has two packages as well in it. Anyone know how to fix this? without using any plugins or something, as my teacher will not have them.
Edit: I managed to fix it, it was because of my classpath had wrong directory
Just export your project in an runnable jar file, then go in cmd and execute:
java -jar .jar

how to run java program outside eclipse on a server that doesn't have eclipse

I wrote a java program that contains many classes in eclipse, it is my first time that I write a code in java and in eclipse too, now I need to run this code on a server that doesn't have eclipse.
Compiling & Running a Simple Program.
This is your best starting point.
Use "File -> Export -> JAR file" wizard to create a .jar file contained your compiled classes. You can then copy this .jar file to your server and use java.exe to run it. Use "java -help" from a command line to get instructions.
Please go through link provided by Andrew
Eclipse is an IDE , it facilitates development but not actually required to run your code, if you want to run your java file in a server somewhere, make sure you have JRE installed in your "server" and in your Path, then run following command in your server's shell environment
javac filename.java
above command will generate a .class file in the same directory, which is actual file that can be executed using following command,
java filename
assuming your code is inside a file called filename.java

How to compile and execute this JAVA application in Ubuntu?

There is a Hdfs.java inside src/hdfs and there is a utility jar file inside lib.
What are the options I give when I compile the Hdfs.java using the utility jar?
And how do I execute?
I went through the examples here and I'm very confused.
If you do not want to use the compiler inside of NetBeans, then go to your terminal application, set your current directory to src and invoke
javac -cp .:../lib/utility.jar Hdfs.java
To run, you would do this:
java -cp .:../lib/utility.jar Hdfs
If you want to compile and run within NetBeans, see Jigar Joshi's answer.
Looks like you are using net beans, right click on project and do clean and build

Categories