I wrote a simple game with 2D graphics in Java (Eclipse) and lib Slick2D. When I export project to Runnable Jar File in Eclipse and try to run this file just nothing happens. I can run this game in Eclipse without any problems. When I write java and put my jar in console to get path and hit enter i have sth like that:
C:\Users\Me>java C:\Users\Jolanta\Desktop\pnd.jar Error: Could not
find or load main class C:\Users\Jolanta\Desktop\pnd.jar
In launch configuration while exporting I selected right main class. Any ideas?
it's command for starting jar file with main class:
java -jar C:\Users\Jolanta\Desktop\pnd.jar
You need to provide native libraries along with the jar file. Here are some scripts that will launch your game:
windows (.bat file) :
java -Djava.library.path="native/windows/" -jar pnd.jar
linux :
java -Djava.library.path="native/linux/" -jar pnd.jar
where your directory will look like this:
your .jar and scripts are in the same directory along with 'native' folder.
not sure where I got this folder from, I can send it to you if you want
Related
I have made a java project in eclipse that's a runnable jar if I export it.
My structure of my project :
When I export my project as a runnable jar it asks me how I would like my dependencies to be packaged and I choose to put it in a lib folder. So when exporting it exports the runnable jar as well as creates a sub folder with my dependent jar files which I want to be only the 5 jars located in Referenced libraries.
This is the export window :
This creates my runnable jar and then a folder _lib with my other jars.
This works fine but as you see in the first image I also included the Tomcat lib library because some of the jar files in tomcat lib are used by my project.
The problem is that when I export, all the jar files in the tomcat lib get exported to my sub lib folder which I do not want.
Basically I want to deploy my runnable to a server witch will get the dependent jar files from the sub directory lib only those 5 jar files in image (Referenced Libraries). Tomcat is installed on the server so it should point to tomcats lib to get the rest of the jars.
Want my project to use the generated lib folder and then the tomcat lib.
Hope it makes sense what I am trying to ask.
Using Eclipse and java 1.7. developing on windows, deploying to linux running the application via command line on linux box.
What I have done to get this working is on the linux side to start the java runable class another way by specifying the classpath this will give the class you are trying to run the ability to first check the folders that you specify. So in my example instead of executing my app on the linux box with the following :
nohup java -jar /usr/local/P6/StockListShunter/StockListShunter.jar &
I did the following and specified the Class path lib that java should check for .jar file dependencies :
nohup java -classpath :/usr/mylib1/*:/usr/StockListShunter_lib/*:/usr/share/lib/*: stockListShunter.Shunter &
Notice I specified 3 libraries java should check when running my runable class, mylib1,StockListShunter_lib and lib.
After you specified the classpath you will see you need to specify your java class witch will be your main method class. In my example it is stockListShunter.Shunter where stockListShunter is my package name.
Just take note that you should make sure that the class you are trying to excecute is included in one of the jar files that you specified in the classpath otherwise it wont find the class and you will get an error : Error: Could not find or load main class stockListShunter.Shunter
So when you run the command the process will be started, my program is in a loop so the process will be alive until I kill it. If your program should be alive you can confirm it is running by running the following command.
ps aux | grep stockListShunter.Shunter
Where stockListShunter.Shunter is your main class name. This should display all the processes where the command has a stockListShunter.Shunter in it.
If you want to end the process like mine that's in a loop you can run the following command.
pkill -f 'java.*stockListShunter.Shunter'
Again where stockListShunter.Shunter is your main class name. This should kill your java process.
Hope this could help some one in the future.
I have a java project which consists on 3 classes(Program,Proxy,Events) from which Program has the main function on it.
I have a Properties file in the same level as src folder.
I want to deploy this project so that i can run it in a cronjob on a ubuntu server but i have no idea how to do so.
1- How do i deploy it? i can only see 3 .class in the bin folder, i thought i would get only 1 output file of some sort.
2- Where do i put my settings file when deployed?
Using Eclipse BTW
From the directory, in a terminal, run java Program to run your application. You'll want your settings file in the same directory (depending on how you are loading it in your code, but if you are loading it as a classpath resource, that would be the spot to put it).
Alternatively, if you want to have a single file, in eclipse, you can export your code to a JAR file:
File > Export > Java > Runnable Jar File
Pick your project
Choose a filename for the JAR (usually ending in the .jar extension)
On the last page of the wizard, choose Program as your main class
To run it, enter java -jar XYZ.jar where XYZ.jar is what you named it.
i'm working in my tablet a project that i want to run in my raspberry pi. The IDE AIDE, that i'm using can't export my project as an executable jar file. so i decided to try that by using the command line
I used:
jar cvf ServerActivities.jar *
too create the jar file whichbworked but when i want to start it by using
Java -jar ServerActivities.jar
it says that my Main class couldnt be found or loaded, but it exists and contains an main method
You need to create a manifest and point to your Main class from there.
See: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
or: How to setup Main class in manifest file in jar produced by NetBeans project
I have created for a first time a programm in Java SWING including RMI Connection with PORT (Server - Client) in Eclipse.
Now I want to export only the Client (to a jar File if its possible ) and test it (via install it) to another computer so I could see if it works and how it works.
The Structure of my project in Eclipse is like :
From there I want only the Client to export and install it to another PC and start the Programm with the LoginForm.java. The .jar export files that have tryed and created they dont do nothing at all. Also dont know if I have to do something specific with the Build Path or the folders (like Image folder) that I have extra create.
JavaMunich:
Hava try it and nowthing happens when I double cliked it
You can't just double click a .jar file, you can execute the program by using the following command.
java -jar YOURJAR.jar
You could make a .bat file with the command in it to make it easier for future executions.
Open notepad.
write :- java -jar YOURJAR.jar.
Save it with the extension .bat.
copy it to the directory which has the .jar file.
double click it to run your jar file.
I want to create .exe file for my java project and give it to my friend. I wrote my project in eclipse and it uses sqlite. I don't know how to make a .exe file that can be run in other PCs.
Can any one help?
P.S:I saw this link but it is not useful for me!
Create .jar of an eclipse project that uses Sqlite DB
.exe is a creature of Windows.
To run a Java program, you typically:
Create a .jar file (the "native" Java library format)
Write a DOS/Windows .bat file (or, equivalently, Linux shell script) to run your Java program (using the Java .jar file)
Optionally, create some easy-to-use mechanism for the end user to download the Java JRE (if it's not already installed on their PC).
Your .bat file can be as simple as this:
start javaw -jar myjarfile.jar
Have you considered creating Runnable jar from eclipse.
In eclipse, go to File > Export > Java > Runnable Jar.
There you ll find some options and you can use what suits you. The jar created should be able to run all by itself (obviously it needs the java run time).
Try this out.
I would recommend using a bat file. You can make a double clickable jar file, but I feel that is sometimes restrictive and not intuitive.
Not many end-users know that a jar file is double clickable.
You need to make sure the jar file has a main class and classpath defined. The classpath section in the jar file sometimes causes issues. Like you cannot reference a file or path on the file system. Only files or folders that can be relatively referenced from the location of the jar file.
For windows users, you cannot easily make an exe file from a jar file. There are methods like using jsmooth, that will wrap your jar file into an exe file (bloating the exe file in the process).
The easiest way is to create a bat file. You can easily convert a bat file into an exe and make the exe file have an icon and everything. Link to a converter here:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
First create an executable jar file by clicking on File menu, then export, and then select runnable jar file.
Then select main class and click ok - the jar file will be created.
After that use Launch4j application to create .exe. Launch4j is the best option for creating an exe file.
Then use Inno Setup Creater to create an installer and it is done.