I'm using number of java files as common in different ADF projects, I want to archive them in jar file so I can import this archive file from any new project to use the java libraries in the project, I tried create it in jdeveloper but no luck.
Thank you for any advice,
You can use the following article to understand the way.
creating a Jar file
jar cf jar-file input-file(s)
But still you can zip a file using windows zip utility or winzip and rename it as a jar file. It is not official but it works.
No matter how big or small you project is, the best answer to this question IMHO is a build tool. I would recommend maven, it is a great tool. It will take some time to get into and it will probably slow down your pace at first but the rewards of knowing how to use a tool like that are very big.
http://maven.apache.org/
from your terminal - go to the directory where you have the files you want to jar and type the command
jar -cf myjarfile.jar *.java
hope this helps
see also:
Creating a JAR File
Assuming that the files that you want to reuse are related to ADF you should read about using ADF Libraries to increase reusability.
See: http://docs.oracle.com/cd/E16162_01/web.1112/e16182/reusing_components.htm#BEIGHHCG
Related
I have this, perhaps, easy problem, but I don't know how to handle this.
I have my Java program and it works pretty well when I call it via terminal (Java command).
The program uses 4 text files from the hard disk which can't be added as resources to the project.
How to do this right so I could build jar file only with main class and files from hard disk (first one is a config file and it has paths to other files so the program knows where they are)?
I'm using IntelliJ IDEA 14.1.4 on Arch Linux.
I did it based on this blog, but it's not working without txt files in src folder.
Also "jar cvf" command builds jar file, but it's not working outside my computer (for example on windows or OSX).
Can anyone help me?
I prefer step by step instruction so I would understand what is going on in here.
I recommend to build your application with Maven and create a Maven Assembly which contains your JAR file as well as the config.txt file.
Is it possible to do any of the following?:
Create a new JAR file from a given .class file?
Insert a local .class file into an existing JAR?
It seems that I would need to somehow read the .class into a JarEntry, but this does not seem possible with any of the existing JarEntry constructors. Is there any workaround or alternative ways of accomplishing this?
Thanks in advance
EDIT: Looking for a programming solution
jar files are just zip files with classes in it. When you have java installed on your machine you can create jar files the jar command.
If you use a java IDE it should have a option to create a jar file from some classes.
But most people use a build tool to accomplish that. Well known and widely used java build tools are Apache Ant or Apache Maven. Apache Ant is probably better to start with if you're new to java and it's tooling.
Using .class files you can extract the source code using JAD decompiler. Then create a new JAR file of your own where you modify as per your needs.
I've written some utility methods to add files to ZIP/JAR files using the NIO2 File API (the library is Open Source):
Maven:
<dependency>
<groupId>org.softsmithy.lib</groupId>
<artifactId>softsmithy-lib-core</artifactId>
<version>0.3</version>
</dependency>
Tutorial:
http://softsmithy.sourceforge.net/lib/current/docs/tutorial/nio-file/index.html
API: CopyFileVisitor.copy
question is: what is included in the executable jar when exporting as such from Eclipse?
I am asking because I would like to know, for example, if I have an image in the project root, would that image be included in the export?
Clarification: I am talking about runnable jar files (edited)
You mean File->Export...->Runnable JAR file? Only the class files are in the jar and - if this option is selected - the linked libraries. You can, however create a source folder (name it "ressources" or so) and this will also be included in your jar.
Eclipse JAR exporter follows JAR Package Specification:
http://docs.oracle.com/javase/1.4.2/docs/guide/jar/jar.html
But as always - the best option to learn is just give it a try.
It's quick and straightforward.
I have a Swing desktop application and have created a jar file which depends on library (which is kept in ./lib/) and a .txt file in the same folder. Now to execute the jar I have written a .bat file which checks if Java is installed or not. If installed then I run the jar file with command:
javaw -jar TagEdit.jar
Now there are two problems I am facing with this:
I would rather prefer a single executable, if possible.
As using bat file, the console is visible in back (looks kind of weird). Is it possible to turn it off?
Java is everywhere, and there are lots of applications that are built in Java and packaged in a setup, or given as exe. I Googled a lot but could not find a way to create a setup for the software or an exe. How are those software packaged?
Have tried jlaunch, but could not get that to work correctly.
Himz, Eclipse can automatically build a so-called "fat-jar" for you. It is a jar that contains all the dependencies you need.
If you are a happy Maven user, then you have two brilliant alternatives - the shade plugin, and the assembly plugin. They both can produce a "fat-jar" for you. :)
There are various answers to this.
javaws.exe will execute the jar without the console appearing behind
But I feel this isn't really the best way.
I think should investigate using Java Web Start, So you create a JNLP file and have it jar downloaded from the web, I think, you can also have a desktop icon.
If you don't want that
I think you can get/buy binary wrappers for the jar.
You could convert it to an executable. Try Googling java to exe.
Once that is done, you could package it up as an installer using NSIS.
I have a jar file which is used in html file as applet. I want to modify the content of the jar file and to rebuild the jar file so that the html will work fine with the new jar file. How can i do this??
I already tried unzipping using 7zip nad modified the source and created the new jar. But when i use it in html it shows some java.lang.Classnotfound error
You can unjar or rejar the classes and source files as you wish.
unjar
jar -xvf abc.jar
jar
jar cf abc.jar input-files
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
Make the changes in the code (.java files), recompile to get the .class files. Then simply replace the old .class files in the jar with the new ones. I usually use WinZip, but you can use whatever app that can handle .Zip files. It should just work.
I've faced cases where the launcher of the app uses some sort of verification and checks for this kind of changes. I had to use a new launch script. This doesn't seem to be your case though.
This is surely possible from the command line. Use the u option for jar
From the Java Tutorials:
jar uf jar-file input-file(s)
"Any files already in the archive having the same pathname as a file being added will be overwritten."
See Updating a JAR File
A brief test shows this quickly updates changes apart from trying to delete the file.
I haven't seen this answer on other threads about modifying jar files, and many, marked as duplicates, suggest there is no alternative but to remake the jar completely. Please correct if wrong.
JARs are just ZIP files, use whatever utility you like and edit away!
Disclaimer: When reverse engineering any code be sure that you are staying within the limits of the law and adhering to the license of that code.
Follow the instructions above to unpack the JAR.
Find the original source of the JAR (perhaps its on SourceForge) and download the source, modify the source, and rebuild your own JAR.
You can also decompile the class files in the JAR. This is a rather advanced process and has a lot of "gotchas".