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.
Related
I have a Java project where I am using json-simple-1.1.1.jar. I'm using IntelliJ and Maven to run my project and I'm using Windows. I set up my classpath for json-simple-1.1.1.jar in my environment variables and I set up the dependencies on IntelliJ. I can run the project just fine if I press the green run button in IntelliJ, but I want to know how to run it in IntelliJ's terminal.
Normally I run my Java file by going to my file's directory and doing a javac MyFile.java, but I know that I have to add something to the command. I've tried something like javac -cp json-simple-1.1.1.jar MyFile.java while I'm in the directory of my file but it doesn't work and I keep getting this error package org.json.simple does not exist.
What terminal command do I use? My actual .jar file for json-simple isn't actually in my project, it's in a different folder in my computer. Would that be contributing to the problem?
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
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
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
My Java app needs 3rd party JARs to run. I can't seem to get it to run from the command line. Its complaining about NoClassDefFoundErrors, despite setting the classpath to what I imagine to be correct. However, when I run it in NetBeans, all is well - it runs as expected. Is there any way to find out the command + arguments NetBeans uses to run my program? This is NetBeans 7.0, BTW.
Should be:
java -jar dist/ProjectName.jar
That uses the META-INF/MANIFEST.MF file in the jar to determine what to set the class-path to.
First, go to project properties > 'run' and select the main class (one with a main method).
Then make 'clean and build' to generate a jar.
and then execute the jar as this
java -jar dist/yourproject.jar
Or you can double click the jar in windows if you have a JRE installed
Choose Run Menu and Clean and Build Project option
Check the output window where you will see one line if text as follows:
To run this application from the command line without Ant, try:
Line below this line will tell you the exact command line which can be used to run this application from command line with absolute path on your machine.
with regards
Tushar Joshi, Nagpur