At my school I am using Notepad++ to write an applet, and I need to package it in a jar so I can sign it. I am attempting to do this with a batch file like this:
CD C:\Users\name\Java\bin
javac className.java
jar cvfm className.jar Manifest.txt classFolder
java -jar className.jar
PAUSE
And then I get a main method not found exception. There is not much I can do in terms of debugging, or opening up my jar, because as I said before, it is at school and so much of the functionality is blocked. I can provide more details if needed, thanks.
Applets don't have a main method, so you cannot run it in the conventional way with the java command.
To run the applet, create an HTML file with the applet in it, and run appletviewer or view the page in a web browser.
You shouldn't run an applet that way. It's not an application to run via the java command, and usually doesn't have a main method (unless you're writing some dual-purpose program). Run it with HTML code. The applet tutorial will show you this, and surely you've read this already.
Related
I'm building a Java tutorial where there is a button when clicked, opens a notepad application which I built. However how do I go about opening the notepad application in the ActionListener? Should I use ProcessBuilder?
If your separate program is a compiled .jar file, use the following code to launch it, but note you will not have any control over it.
Runtime.getRuntime().exec("java -jar 'path/to/file.jar'");
Note this method returns a Process object, which you can then modify to your individual needs.
I am writing a java program and try to ship it as a MAC app. I have successfully built a simple testing jar file (for test only) and package it by AppBundler. However, when I try to package my real program, the app just crashes (disappear after it is executed) without any error message. I am wondering if there is any way to get the error message dumped by my jar file so I can understand what is the issue to solve.
BTW, I execute the app(jar bundled) by just clicking its icon. There is nothing shown but getting a useless message, "unknown exit code 1", in my Console.
Could anyone let me know how I can get java output back when I execute it as a bundled app?
EDIT: my app works when I manually find the jar file (ex: XXX.app/Contents/Java/XXX.jar) inside app bundle and do "java -jar XXX.jar" but it crashes when I execute the app directly. I suspect the problem is caused by referencing the wrong resource directory but there is no java error message, making the debug nearly impossible.
You can run your program with Java on the command line like so:
java -jar yourjar.jar
If you want to try running your main class explicitly, do this:
java -cp yourjar.jar your.package.MainClass
If it fails with the second command, the classes were not packaged in the jar properly. If it works, there's something wrong with the manifest file.
I created a GUI in the NetBeans and Then a jar file is generated. Now, when I click on a button to run the program with the jar file, there is no operation after clicking and the results that are tables and graphing data types did not show. How I can fix this problem.
Thanks.
There are different ways to export a program. You can use it as a java application or an appelet. You probably made it into an appelet when you really want a separate application.
But without you telling us how you made the jar file or what the program is, my guess is as good as anyones.
After you compile the program successfully, you can run it. Assuming that your program uses a standard look and feel — such as the Java, Windows, or GTK+ look and feel — you can use the interpreter to run the program without adding anything to your class path. For example:
java HelloWorldSwing
For programs that use a nonstandard look and feel or any other nonstandard code package, you must make sure that the necessary classes are in the class path. For example:
Solaris/Linux
java -classpath.:/home/me/lnfdir/newlnf.jar HelloWorldSwing
Microsoft Windows
java -classpath .;C:\java\lnfdir\newlnf.jar HelloWorldSwing
I have the following package on Eclipse:
com.mortgageapp.projects.app
I'm not interested about the package format at the moment, it's just testing. But I'm wondering how to run the app from the terminal (Windows and Mac)?
It contains a Main.java file where it will begin so I have tried locating and entering the src folder. Then doing something like: javac com/mortgageapp/projects/app/Main.java (or: javac com/mortgageapp/projects/app/*.java).
Just wondering if this is current as when I then do: java com/mortgageapp/projects/app/Main I get a few errors.
Your compilation is probably okay, but to run it you need to specify the class name, not a filename:
java com.mortgageapp.projects.app.Main
That's assuming the current directory is in the classpath. If it's not, you may need:
java -cp . com.mortgageapp.projects.app.Main
I assume you are writing an RCP application.
Export the project as a RCP application (click the "export" link in your product configuration). You should get a runnable application file.
If you really want to run the application from the terminal, you need to use the main function in the EclipseStarter. But you don't want to go there unless you are doing something very special.
I'm making a simple card game server in Java using eclipse. I'm now trying to get it to run outside of eclipse.
I did the following
exported it as a jar file, called car4dgameserver.jar
tried to run it by typing java car4dgameserver
I keep getting a error that says
Error:could not find or load main class car4dgameserver
any help on this would be great!
What you need to do is execute it like so:
java -jar card4dgameserver.jar
Hope that helps.
You need to use the -jar option and provide the path to the jar file:
java -jar car4dgameserver.jar