How to build a .jar file - java

Please note I do not mean building a .jar file using an IDE such as eclipse.
What I'd like to accomplish is creating a .jar using my program. For example the user enters some information and then click "Build" and a .jar file would be built and would have that information that the user enters.
I was thinking about maybe saving a file with a .java extension and writing lines of code to that file and then use cmd to build a .jar file.
That's not really the solution I want to use as I'm sure there is a better way to do it.

Take a look at
https://github.com/Quillion/Engine/blob/master/jarIt.bat
This is what I use to pack my jars. You can also learn more about it by reading documentation

Related

Ship and call a .exe from within a .jar [duplicate]

I have a huge JAR file, which I created with Maven Shade plugin.
I run this with java -jar foo.jar , and my UI opens. Now I want to execute *.exe file, which is also in that JAR file, how can I do this?
I tried putting the exe to my classpath and run it from there, but after trying I found out that classpath is actually the location, where my JAR is.
Any suggestions?
Found this thing here, but is this really the best solution? Seems like alot of work, I think I have different case here, because I can define the location of exe myself and the JAR is created by me.
run exe which is packaged inside jar
Why I need this?
I want to give user a single file executable, which he can run, but my program is using the *.exe. Should I put the exe next to my jar and there will be 2 files or there is solution for my requirements?
Copying the file to a temporary location and running it is the way to go. The answer you linked to does much more work that necessary, as you can get your exe file as an InputStream and copy it to a file with a utility like Apache Commons IO FileUtils.copy(in, out)
See How do I copy a text file from a jar into a file outside of the jar? for example.
It's not about the location, it's about the fact that you need to tell your OS to run the exe and, unfortunately, you can't do that by providing a location within a jar.

How to properly make jar archive to run Java program on different systems?

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.

My class cannot find a python file in the jar

I have a jar file that launches a python script. It works if my jar file is at the root of the working directory. If I move it out of the working directory, it cannot find the python script anymore. Why does my call to find the script file not look inside the jar? I use ./(the path). Why does it automatically look in the working directory? I thought it would be self-contained.
Reposting my guess as an answer:
Are you looking for the python script as a file? or as a resource? You might want to share more information about your problem because right now all anyone can do is guess. My guess is that you're trying to read the Python script as a file, and files don't exist inside of jars. To solve this, either read the Python script as a file outside of Java, or look for it as a resource inside of the jar. If the latter, I'm not sure if you can run the script or not.
For more, please see this link: stackoverflow: can-i-make-a-jar-execute-a-python-script
Another clever option: stackoverflow: how-do-you-invoke-a-python-script-inside-a-jar-file-using-python

Extract a JAR file, possibly with WINRAR on CL

I need to be able to extract jar files on the command line.
Piece of cake, you might say. Yes, except I need the extractor to rename same-named files.
To be specific, the Jar file has a file named:
classAX.class
and another named:
classax.class
in the same directory. I need it to extract them both, and preferably rename one:
classax (2).class
or something similar.
It must be able to do this without any user intervention.
Winrar has this capability, but when attempting to extract with unrar.exe, it says that the input file is not a valid RAR archive. (Though winrar has jar capabilities.)
Any way to force winrar to accept jars via command line, or perhaps another program?
Thanks,
~Kurt Nauck
You can develop your own programme in java, there is a Zip package that can deal with compressed files, an also you can deal with a rest of your needs
7Zip command line util accomplishes this perfectly. Thanks for the answers.

Convert .jar file to JAVA DOC

How can I put my jar file to web. i.e is there a software that decompile jar file and make html pages of it?
In other words I want to make a java doc.
[Edit according to user comment]
So you want to extract javadoc from a jar...
First you must understand that if your jar doesn't contain the sources, but only the compiled code that your javadoc will not show any comment.
Then you just need to extract the file in your jar using any zip program (for exemple on windows, rename file to .zip, and extract it).
Last thing to do, is to call the javadoc tool on it. Like other said you can use an IDE for that, or simply call from the command line :
http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/javadoc.html#examples
javadoc -d \home\html -sourcepath \home\src -subpackages java -exclude java.net:java.lang
Creating Javadoc the way it was intended works, as far as I know, only from sources. If the JAR file also contains the source files, then it's just a matter of writing a Java program that opens the JAR file and puts any source files through the javadoc utility.
Interesting idea, but I don't know of anything doing that at the moment. To my knowledge it is however possible to generate Javadoc from inside of java program.
Another approach would be to load the classes into your classpath and use reflection to figure out methods, fields, etc. It will give you a rough overview of the classes, but sadly not the detailed stuff "normal" javadoc generation gives you. A lot of information is discarded upon compilation.
Converting .jar file to html seems impossible, except if you intend to users to download the .jar file from the web. However, html to .jar is possible.
I am certain that only the java source can be converted to javadoc. See here to convert java source to javadoc.
I have created a JAVADOC from a jar file that is not created by you i.e you don't have its source code.
Its simple but tricky.
Get source code from .jar file by using java decompiler. I use JD-GUI | Java Decompiler
Make a new project in myEclipse and copy the 'source code' in source folder.
In project menu you will see Generate Javadoc. Click and select you project and follow the steps. Java doc will be ready after you finish it.
Cheers
Imran Tariq
Once you downloaded your APK file , You need to do the following steps to get a editable java code/document.
Convert your apk file to zip (while start your download don't go
with save option , just go with save as and mention your
extension as .zip) by doing like this you may avoid APKTOOL...
Extract the zip file , there you can find somefilename.dex. so
now we need to convert dex -> .class
To do that, you need dex2jar(you can download it from
here , after extracted, in
command prompt you have to mention like,
[here] (Keep in mind that your somefilename.dex must be inside the same folder where you
have keep your dex2jar.)
Download jad from
http://www.viralpatel.net/blogs/download/jad/jad.zip and
extract it. Once extracted you can see two files like "jad.exe" and
"Readme.txt" (sometimes "jad.txt" may there instead of "jad.exe", so
just rename its extension as.exe to run)
Finally, in command prompt you have to mention like [D:\jad>jad
-sjava yourfilename.class] it will parse your class file into editable java document.
Use mvn javadoc:javadoc in Maven.

Categories

Resources