I have seen other posts about this but I honestly don't know what to do with that information. Can someone explain to me what exactly I need to do please?
I'm using JCreator
With JCreator you can follow the below process.
Click on Configure/Options.
Click on Tools in the left column.
Click New, and choose Create Jar file.
Click on the newly created entry Create Jar File in the left column under Tools.
Edit the middle line labeled Arguments: it should have
cvfm $[PrjName].jar manifest.txt *.class
Click OK.
For more information you can refer this article
Assuming you are using eclipse: Right Click on your project->Export:
Export it as an executable JAR. That will allow you to run your program directly from that jar file.
It really comes down to what IDE your using, some have that ability, directly under the menu "file" or "project", where you can them select "export as". Some IDEs however, do not have that ability and only allow you to export as a jar file. If that's the case, you need a third party software to do that for you.
An IDE is the platform you are using to debug your code.
Related
I have three classes, one of them is called Main and contains a main method, and no package. The IDE I use is eclipse. If I click File > Export and then select Java > Runable JAR File I'd expect to get a file that I can double-click and that'll run my program. However, that's not the case. If I click the resulting file nothing happens. I'm very new to this whole thing, so my questions are: Is this file even supposed to be clickable, or am I missing a step to run it? If that's the case, how to I convert the file to a .exe file (I really don't get this manifest-stuff, so please explain in detail how that needs to be done)? Basically: How do I create an executable (executable as in "works if i just click on it") file from three classes (with eclipse if possible)?
Edit: It's a console app.
I've run .jar files before, but I've encountered a "different" situation, and I'm not sure what to do. I'd appreciate if someone could help me out.
Previously, I programmed with Java 6 and Eclipse Juno exported all my programs to runnable jar files. I'd get a .jar file that I could run by just double clicking on it. The files always looked something like this (note the jar file icon):
Recently, I wrote a program in Java 8 with Eclipse Luna (Release 4.4.0) and exported it to a runnable jar file, and I got something different (note the different file icon):
It no longer runs when I double click it. Instead, my computer uncompresses the jar, as it would a zip file. I tried running it from terminal. I cd'd to the directory and typed
java -jar graph3D.jar
I got the following error message:
Error: Unable to access jarfile graph3D.jar
After uncompressing the jar file, I found a folder named META-INF with the manifest file, MANIFEST.MF in it. It was the only file that seemed to resemble an executable file. Do I have to do something with that?
Could someone explain how I can run the second jar file graph3D.jar? Is it something new with Java 8, or something different about Eclipse Luna, or something else?
(Both programs run fine in Eclipse, by the way)
Thanks for your time and help.
Edit:
Below was the dialog box Eclipse displayed if anyone is interested.
Selecting "Use .jar;.zip" makes the filename "graph3D.jar;.jar;*.zip" .
Selecting "Use .zip" makes the filename "graph3D.jar;*.zip"
Selecting "Cancel" doesn't let you go forward.
You'd have to manually delete the extra file extension.
Somehow when you exported the file, the filters for the file dialog box (*.jar;*.zip) got attached to the filename, which is graph3D.jar;*.jar;*.zip, not graph3D.jar. Java can't find it because it doesn't have the name you supplied. Rename the file and pay close attention next time you export; either you fat-fingered something, or you're triggering a significant bug that needs fixing.
I recommend that you will access the build folder after you've built your project on the IDE under your project folder (in your workspace) and copy both the libraries folder and the .jar and post them wherever you want the program to be "installed", you'll then have an executable jar that should run smoothly without problems, just as I said don't forget the lib folder.
I think there is nothing new in Java 8 related with the running jar, I guess you need to check the the Eclipse export issues, it seems your classes are missing from your second jar file.
I have a java project and i need to create jar file from my project . any body can tell me what is the simplest way to make this?
The basic format of the command for creating a JAR file is:
jar cf jar-file input-file(s)
The options and arguments used in this command are:
The c option indicates that you want to create a JAR file.
The f option indicates that you want the output to go to a file
rather than to stdout.
jar-file is the name that you want the resulting JAR file to have.
You can use any filename for a JAR file. By convention, JAR filenames
are given a .jar extension, though this is not required.
The input-file(s) argument is a space-separated list of one or more
files that you want to include in your JAR file. The input-file(s)
argument can contain the wildcard * symbol. If any of the
"input-files" are directories, the contents of those directories are
added to the JAR archive recursively.
The c and f options can appear in either order, but there must not be
any space between them.
From scratch.. with CMD
The command line is what almost every other application will use to build your JAR file. They just wrap it up a little nicer for you. In truth, it's very simple to do yourself. Obviously Java have explained this way in detail so there is no sense in me repeating it.
Note: You need to have your JDK/bin directoy appended onto your %PATH% system variable to be able to use this method.
Double Note: As pointed out in the comments, I'd suggest you keep trying this method until you understand it. It is very important that you get these things at a low level, so if something goes wrong with the IDE, you have a much better understanding of how to solve it.
Eclipse
Eclipse offers a nice interface for it. You can find a step by step tutorial here. The long and short of it is..
Right click on Project -> Export -> JAR File -> Select the Java files to include
When you've done this, hit finish and you're golden. The tutorial also adds some additional tips in to make it as seamless as possible.
IntelliJ IDEA
My personal favourite IDE. This question offers a nice explanation for how to export as a JAR file. Again, the long and short of it..
File -> Project Structure -> Artifacts
In there, you can then create a new artifact by clicking the + icon. This will give you an option for the file type, which is .JAR and which modules you want to include in your artifact. When you're done, you go to..
Build -> Build Artifacts
And it will create the JAR file from your project.
Using Maven
I've often found this to be a pretty awesome tool, and definitely one worth considering. In IntelliJ, by double clicking the install procedure in the life cycles..
This will create a new JAR file in your .target directory.
Note: Some IDEs (like IntelliJ) will hide the .target directory by default. Make sure you make it visible in the project settings.
A JAR file is nothing but a ZIP file with added meta-information for the Java Runtime Environment. So the easiest way is to actually zip your classes files including that META-INF folder by hand, then rename the file to JAR. How you get your classes files however is a different story.
The easiest practical way is to hit the build button in your IDE, which will then compile your code into class files, create an appropriate set of meta information and then conveniently zips the whole thing into a JAR file.
Asking for a maven solution, you would need to specify a single pom.xml in your project
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>you.specify.something.preferably.a.domain.name</groupId>
<artifactId>name-of-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
And with this you can do a
mvn package
To build the project. However, it relies on a lot of defaults, you would probably want to differ.
To build a jar file from a module
On the main menu, choose Build | Build Artifact.
From the drop-down list, select the desired artifact of the type JAR.
see this
Although this seems an easy thing I'm not able to find the answer for it.
What I'd like to achieve is simple. I have a folder with java source files and I want to edit them using eclipse within a new project. But at the time of running the application I don't want eclipse to use the workspace project folder as "root", instead it should use the folder with the java source files.
The effect should be like opening the source files with a text editor directly and changing them, but instead this should be done through an eclipse project but still use the original folder to run the application.
I just want to have all the advantages that come from editing source files within an eclipse project instead of using something like notepad++.
I tried linking the source files and changing the relative path to the source directory but it doesn't work. When running the application it needs xml files which exist in the directory but because it's running "from" the eclipse project folder it doesn't find them.
I'm not sure I really understand what you want to do, but sounds like you want to set the run configuration's working directory: Open 'Run Configurations', choose the class containing your main method (or create a new run configuration for that class first if it's not yet there), then specify the Working Directory on tab 'Arguments'.
I do same with all my projects. What you need to do is :
Create workspace directory on different location than your source code.
Import your source code in your workspace directory. Here don't copy source to your workspace
EDIT
In Eclipse
Go to File->Switch Workspace->Other-> Type "new directory workspace" path, click OK. Eclipse will restart.
Go to File->Import->General-> Existing Projects into Workspace-> Next-> Select Root directory
Eclipse will list your project, select it.
Start editing and saving files.
Thought this does not directly answer your question, as an alternative to using Eclipse IDE for Java files try using Padclipse which is a text editor based on Eclipse.
Padclipse is a light weight text editor based on Eclipse. The basic
product is composed of Eclipse RCP plus Text Editor, Compare and
Search facilities and their dependencies. A few additional third party
plug-ins are included as well.
Check it out here
Also, the default JDK on my system was a 64 bit because of which starting up padclipse failed. Create a padclipse.ini in the folder where you unzipped it in and put in the following contents :
-showsplash
-launcher
padclipse.exe
-name
Padclipse
--launcher.library
plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.0.v20070523\eclipse_1017a.dll
-startup
plugins\org.eclipse.equinox.launcher_1.0.0.v20070606.jar
-vm
C:\dev\jdk\1.5\1.5.0_21\jre\bin\server\jvm.dll
Change -vm argument to point to the java.exe or jvm.dll of a 32 bit jdk.
I am using Eclipse & have some packages that I want to export into a JAR file (not a runnable ones). I just need it so I can import it into another Java project to use the classes.
When I exported them, most of the packages are exported but there are a few packages that appears to be empty. I've selected Export generated class files and resources and Export Java source files and resources. I also tried changing the option here and there just to figure it out but it still gives me the same results.
Is there a configuration that I missed?
You would probably be better off reusing Clean way to combine multiple jars? Preferably using Ant (that's what Eclipse is trying to do, under the scenes).
When you right click on a project, then pick Export ... you can in the following menu choose Export as Java>JAR File.
Then a menu should pop up, which lets you exactly choose from a list which folders/files you want to export into the JAR. (On the left, as Select the resources to export.)
For exporting...
1. Goto File -> Export.
2. Under 'General' category select 'Archive File'.
3. Give name and path for where to save the archive.
For importing...
1. Goto File -> Import.
2. Under 'General' category select 'Archive File'.
3. Browse the exported archive.