Trying to run java program for first time outside Eclipse - java

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

Related

Program cannot find class when ran [duplicate]

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.

How to run a Jar-file with external libraries?

When I run the Jar-file inside netbeans it works.
But after I clean and build it, it won't run.
It gives me an error, that the Mainclass couldn't be found.
I tried already something like:
java -cp C:\javaProjectsTests\J.jar;C:\javaProjectsTests\lib\*;. j.J
java -Djava.library.path=C:\javaProjectsTests\lib\* -jar C:\javaProjectsTests\J.jar
Maybe someone could help?
Please refer below link
Execute jar file with multiple classpath libraries from command prompt
Lod your jars to classpath and execute your class (with main method)
Thanks,
It was a syntaxerror in the path-string.
It works now, but only if the lib-folder(other jar-files) is in the same directory as the executing jar-file. Should not a problem for comandline programs, as it's possible to use a batch-file to execute from somewhere else.
However I asked me if it's possible to merge archives, as I could read on a website here ?

Get Java system output after the jar file is bundled (by AppBundler in MAC)

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.

can't find main class java program with two jar files?

This is a pretty basic java question but I'm very new to java. I'm trying to follow this guide:
http://www.egtry.com/java/database/jdbc/hello_teradata
my jar files are located in:
tdgssconfig.jar located in /prod/user1/home/tdjar
terajdbc4.jar located in /prod/user1/home/tdjar
I created a file called tdTst.java in /prod/user1/home/tdjar dir with the script in the link above.
I than ran
java -cp ./:terajdbc4.jar tdTst.java
as well as
java -classpath terajdbc4.jar:. tdTst.java
but keep getting this error:
Error: Could not find or load main class tdTst.java
I'm new to java here so what am I doing wrong here? Do I need to point it to both jar files?
Putting the comment as a separate answer as suggested by #rkosegi
Use java -classpath terajdbc4.jar:. tdTst , without the .java

Java - Eclipse packages

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.

Categories