I am using IBM Websphere, and from here i can just click Run As java application, and the program runs inside websphere. But i want to run the program outside IDE.

I created a jar file and everthing is correct with it. It has the MANIFEST.MF and all.

So what do i need to do to run this from cmd.exe? I would like cmd to open when the jar file is double clicked so that the program will use the command line as the input?

import java.io.*;	// Java I/O classes
public class L3P3
{
	public static void main(String []arg) throws IOException		// throws IOException
	{
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		System.out.println("Enter in your full name");
		String s1 = input.readLine();
		StringBuffer tmp = new StringBuffer(s1);
		String s2 = tmp.reverse().toString();

		System.out.println("Your reversed name is " + "\"" + s2 + "\"");
	}
}

Thanks, sj

Dani AI

Generated

wanted to run a small console app outside WebSphere and have a command window available when the JAR is launched. Several replies already pointed at the two usual causes: how the JAR is packaged (the manifest / entry point) and how Windows launches JARs (no console by default). The following practical checklist fills gaps left in the thread and gives concrete, verifiable steps.

  • Verify the JAR actually contains the launcher class and a correct manifest. Use the JDK jar/unzip tools to inspect the archive and to print the manifest so the main entry can be checked:

    jar tf myapp.jar
    unzip -p myapp.jar META-INF/MANIFEST.MF

    If the manifest is missing or the main class name is wrong, recreate the JAR with an explicit manifest (the jar tool can combine a manifest file with class files).

  • Common manifest pitfalls: the main-class must be the fully qualified class name; lines must not have extra spaces; the manifest must end with a newline. Multiple manifests (from libraries) can also confuse the JVM when exported incorrectly from an IDE.

  • How to get a console when launching from Explorer: run the JAR from a command shell, or use a tiny wrapper script so double-clicking opens a real console that the program can read/write. For a packaged, double-clickable solution that still exposes stdin/stdout, use a lightweight native launcher (for example, Launch4j) which can wrap the JAR in a Windows EXE and optionally attach a console.

  • Eclipse-specific notes: when exporting from Eclipse, use the runnable-JAR export (or the JAR export with the "generate manifest" and explicit main class) and choose how libraries are packaged (fat JAR vs external libs). Wrong packaging is the usual reason for “failed to load main-class” errors reported by .

Quick troubleshooting checklist: confirm JRE/JDK on PATH, list JAR contents and manifest, confirm the launcher class exists at the expected path inside the JAR, ensure manifest formatting is exact, and if the app needs third‑party jars either put them on the manifest Class-Path or bundle them into one runnable jar.

Reference: Oracle’s JAR/manifest documentation (JAR file guide). Launch4j for native wrappers: (https://launch4j.sourceforge.net/).

Recommended Answers

All 4 Replies

if u want to run ur jar from cmd means just run like this just go to ur file location through cmd and then type

javaw -jar filename.jar

or
java -jar filename .jar

main thing is your OS should hav JVM otherwise jar file wont run

ur has nothing to do with it. Java didn't exist when people were living there.

to make an executable jar, you need to provide the Main-Class attribute in the manifest file inside the jar.

Thank you for this was helpful to me.
But I tried like

[B]Java -jar blpack.jar [/B]

like you said but it giving error

Failed to load Main-Class manifest attribute from blpack.jar

Please any body help me? I used Eclipse3.2.2

I used this to learn how. The author explains it very well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.