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.
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 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've been working on a processing application using ControlP5 and Twitter4j. I want to have my project run from a single jar file from any operating system. Basically I want to package up my application. My application uses images. I've been browsing for more than an hour, but I cant find how to do this. Any suggestions?
using
processing 2
twitter4j3
Thanks in advance!
I dont know if you can directly do it from the Processing IDE however, if export your sketch to a Java applet then locate the .java the the sketch folder you can use this in conjunction with Eclipse to export to a jar file.
So, I know that this post is very old but if you are still looking for a solution, or to other people that see this thread, it's relatively simple.
Export the project
In the folder with the exported project (something like application.windows64), navigate to lib and find core.jar and project name.jar (you need to have file name extensions visible)
Rename the files to .zip files
Extract core.jar to whatever folder
Extract project name.jar into the same folder (make sure you don't do it into a subfolder)
Click yes if it asks if it wants you to replace a file (if it doesn't you extracted the files incorrectly)
Delete core.jar and project name.jar
If the project uses images, move them into the same folder as all the other files
Select all of the files in the folder, right click, hover over send to and select compressed (zipped) folder
Rename the .zip file to name of project.jar
This might be old, but i still find other posts about it on processing forums.
This is the best way to run processing project as a jar file.
When exporting application, you will always end up with a lib folder inside exported application(whether for Linux and Windows). For windows, open command prompt(or power shell), you can use right-click+shift and then click on open power shell here.
After that you can run the following command.
java -classpath lib\* DisplayDepthStream
Now DisplayDepthStream is the name of sketch file.
To explain the command, -classpath lib\* tells java to add everything under lib directory to the class path. And DisplayDepthStream is the name of my main class.
Hope this helps~!
Chears
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.
Hi I have created a java application and created a jar file. Then I created a batch file eg-> startup.bat The contents of this file is java -jar MyApp.jar
Now if I double click the batch file then my java application works because both the jar file and batch file belong to same directory. Now I copied the batch file to desktop and run then My application did not run.
Also I want My batch file automatically set the class path.
How to create a batch file with all the above feature
Thanks
Sunil Kumar Sahoo
If the jar is an executable JAR (which it seems to be from your example), you should be able to just double-click the JAR file. If this does not work, you shoud associate the java executable as the program with which to open a file with the .jar extension. See Tools > Folder Options > File Types from an explorer window.
In order that a program be "distributable", it would normally be packaged (i.e. the JAR file and startup scripts) in some ZIP archive and then extracted to a folder on a user's PC. Your startup script should provide a relative path to the JAR file. For example if you have organized the contents of your ZIP into lib and bin folders:
MyProject
+--- lib (contains jars)
+--- bin (contains .bat script)
In this case, the startup.bat file should reference the Jar as:
%JAVA_HOME\bin\java -jar ..\lib\myapp.jar
This requires that any users:
Have a JRE installed on their system (unless you package that up as well)
Have java on their path or a JAVA_HOME environment variable set
The problem is that the batch file doesn't know where the jar is, it is looking relatively from its own path. You could copy the jar file to your desktop, too.
If just want an icon on your desktop, make a shortcut to the batch file rather than a copy.
Aslo if you application is quite complex (size more than 1+GByte) - you can distribute it with jre included.
Because it's a bit long to copy in here, I'd suggest that you have a look at what Squirrel SQL does. And you'll have a very nice cross-db tool as an extra bonus ;-)
They enable the tool to be started in two possible ways:
by starting the jar itself, classpath info will then be fetched from the manifest file (see here for the details, look up download extensions). In that case, after unzipping the hierarchy of files as explained by other posters, just make a shortcut on the desktop and you're all set
with a batch file. You'll see that the batchfile solution is quite complicated, especially the construction of the classpath.
So I'd go with the first solution.
I understand that you would like to distribute your application to multiple machines? A (very) simple solution would be to create a zip/tar/whatever archive that has all the needed jars (including MyApp.jar) and the startup script.
In the script you can use the -cp option to set the classpath to the jars:
java -cp needed.jar:needed2.jar -jar MyApp.jar
As said above, making a shortcut to the desktop is a better option than copying the script itself.