Run jar file from unix command prompt (ERROR) - java

I have a java project that has 10 .java files. A1.java, A2.java......A9.java and Main.java.
The project contains a package grand.big.medium.small and all the .java files are inside this package.
I have compiled and created an executable jar file for the project using:
javac grand/big/medium/small/*.java
to run the project I used the command
java -cp . grand/big/medium/small/Main
to create the jar I used the command
jar -cvmf manifest.txt MyJAR.jar *.class
I want to run the jar file from command prompt and I am using the commad
java -cp . -jar grand/big/medium/small/MyJAR.jar
and I getting an error:
Error: Could not find or load main class Main
please can anyone tell me why I am getting this error?

Run as:
java -cp . -jar grand/big/medium/small/MyJAR.jar grand.big.medium.small.Main
Assuming you have grand as a directory within current directory and directory hierarchy follows.

Related

Cannot run a .jar file

I'm having issues when I try to execute a .jar file. I always get the message from the command prompt "cannot find or load main class" every time I try to run the file I have just compiled.
I have tried the following(using the command prompt and saving the java code with Notepad++ and creating the manifest.txt file in the same folder where the .java code was saved):
javac classname.java
java cfm classname.jar manifest.txt classname.class
java -jar classname
I have also tried:
javac classname.java
java classname
And:
java packagename.classname
After compiling the .java file
I know there are hundreds of questions like this in the forums, but I have looked everywhere and I keep getting the same error. I just cannot run the .jar file even after I create it.
It's probably something I have missed but I am out of ideas.
Manifest:
Main-Class: classname
Let's see.
java -jar classname.jar
would work if your MANIFEST.MF calls out the correct class.
java -cp classname.jar my.package.MyClass
would work in any case.

Ini4j classpath no class

i am want create jar of my project using cmd line.
I am using ini4j libs.
Everything compiles fine, but I do not know how to set the -cp to the library.
Compile:
javac -cp ".;lib/ini4j-0.5.2.jar;ini4j-0.5.2-jdk14.jar;lib/ini4j-0.5.2-jdk14.jar" gui_Frame/*.java
Create jar:
echo Main-class: gui_Frame/MainApp > manifest.txt
jar cvfm GVE.jar manifest.txt gui_Frame/*
But, if i want start java -jar GVE.jar i get following error:
Java.lang.NoClassDefFoundError: org/ini4j/wini
What am I doing wrong ?
You must specify the same classpath when running java as you did when compiling.
Or bundle all the necessary class files in one JAR.
==EDIT==
Try this:
java -cp "GVE.jar;.;lib/ini4j-0.5.2.jar" gui_Frame.MainApp

wsgen 'Class not found'

This is the setup of my java project
I'm trying to run wsgen through cmd:
wsgen -keep -cp . com.library.webservice.HelloWorldImplementation
But I'm getting the error
Class not found: "com.library.webservice.HelloWorldImplementation"
Also, the command is running from C:\ ... \WebServices Test\src
Any idea what I'm doing wrong?
C:\ ... \WebServices Test\src contains the Java source files, not the class files. The classpath specified via -cp should point to the directory that contains the compiled classes, typically the bin folder. Therefore you should run the command from that directory.

A java Exception has Occurred when Running .jar File of GUI

I have created a GUI project and compile the program using CMD.
For Creating .jar File, I created manifest.txt and made the jar by using following command:
jar cmf manifest.txt Client.jar *.class
this created a .jar file but when I open the Client.jar a Window pops up saying
"A JAVA Exception has Occurred" but when I run the jar from CMD
java -jar Client.jar
It runs properly from CMD but not by clicking on it directly.
What Could be wrong ....?
This is my manifest.txt
Main-Class: ClientTextEdit
\n
\n
\n----> newline
these are the .class files:
ClientTextEdit.class
ClientTextEdit$1.class
ClientTextEdit$2.class
ClientTextEdit$3.class
ClientTextEdit$4.class
ClientConnection.class

JAR file not Running Properly

I have created a runnable jar file that contains the following classes:
Main.class (This contains the main method)
Form.class
WrapLayout.class
The manifest file (Manifest.txt) contains the following:
Main-Class: Main
(It has a new line at the end)
I have created the jar file using this command:
jar cfm Organizer.jar Manifest.txt Main.class Form.class WrapLayout.class
The jar file is created, but when I run it, the command window opens up for a split second, closes, and nothing else happens. The file is a swing application, and I am running Windows XP on Parallels Desktop for Mac, but I don't think that matters. Does anyone know what's wrong?
EDIT: I tried running the jar file in mac, and I got this error message in the console:
Exception in thread "main"
java.lang.UnsupportedClassVerionError: Main : Unsupported major.minor version51.0
follow these steps an test:
Start Command Prompt. Navigate to the folder that holds your class
files: C:>cd \mywork
Set path to include JDK’s bin. For example: C:\mywork> path
c:\Program Files\Java\jdk1.5.0_09\bin;%path%
Compile your class(es): C:\mywork> javac *.java
Create a manifest file: C:\mywork> echo Main-Class: YourMainClass >manifest.txt
Create a jar file: C:\mywork> jar cvfm YourMainClass.jar manifest.txt
*.class
Test your jar: C:\mywork> YourMainClass.jar

Categories

Resources