This question already has answers here:
Is it really impossible to protect Android apps from reverse engineering?
(10 answers)
Closed 7 years ago.
I am Android developer.
I have created a .jar file from Java project with below steps
Right Click on project and select export option.
Selected jar file from Java folder
Clicked on finish. Then mysdk.jar is created on desktop.
When I pasted this jar in lib folder of Android Project. When I selected(ctrl + left click from mouse) any method presented in jar from AndroidProject/src/demo.java , It is showing source code of .jar file.
My requirement is to give this jar to Third Party Company who should not read my code.
So, I want to hide my source code of jar. but how ? Please some one help me.
I am using Android Studio.
Thank you in advance.
Extract the created jar file and check if only contain the class files or source file. Actually it shouldn't contain source files in jar files. If it contains , make use of jar command in shell/command line to create jar file and deliver it. Also check the new project is linked the previous project because both exists in the eclipse.
jar -cvf <jar file name> files to be archived
Related
This question already has answers here:
Self exploding and rejaring jar file during execution
(2 answers)
Closed 3 years ago.
I am currently using the java class Preferences to maintain preferences inside of our java application. It is simple, and currently only contains 2 key/value pairs. Some of the higher ups on this project have requested to keep the preferences.xml file inside of the JAR, to make it a clean running, so everything would be self contained within the JAR (users do not need to be able to access this file).
I know that preferences has an import using an InputStream, and an export using an OutputStream. Is there anyway to edit the file inside the jar using the outputStream?
A JAR file is a zip folder, so it can be extracted and worked upon using the java.util.zip package.
However, a running jar may be write protected, preventing content modification.
It is better suited to store configuration in a corresponding location in the operating system. On windows, the common location is the windows registry.
There is a Java library for editing the registry as shown in this answer .
Library Source: https://github.com/apache/npanday/tree/trunk/components/dotnet-registry/src/main/java/npanday/registry
To store config on other operating systems, you can use a file inside a folder named after your application.
Common Location on Linux: '~/.config' folder
Common location on Mac: '~/Library/Application Support' folder.
I don't think it's possible to edit a file inside a jar using OutputStream.
What you can do is this:
You can import the file, edit it and add it back to the jar file.
For pushing a file into jar, refer adding a file to jar
This question already has answers here:
How to includes all images in jar file using eclipse
(4 answers)
Closed 6 years ago.
I have an image file which I want shown as a JLabel in a JFrame for a program that will be on several computers running the same code. The image would not be on the computers already but would somehow be stored as a program file. The computers would all be windows. To insert the image a file path has to be given, but I'm not sure what this will be considering the computers are all different.
I have done this before on a different language by having the program find the program's directory and doing some string manipulation, but I have not been able to do this yet on java and would like to know if there is a better way.
Here is the statement that the path has to go into:
lblTitleBG.setIcon(new ImageIcon(file path goes here));
lblTitleBG is a JLabel.
First you create a source folder inside your project using eclipse or your preferred IDE. That will create a physical folder in your project folder that you can navigate in and move your files.
Let's say you have Project1 where you create Files_Folder. Now you navigate to the Project1 folder with window explorer and paste the files you need inside the Files_Folder and in the bin folder too. After this, just go back to eclipse and refresh/clean project. Your new moved files will appear in the Files_Folder in eclipse explorer too.
Just use lblTitleBG.setIcon(new ImageIcon("Files_Folder/image.png")); after following all the steps and you will have portable code.
Try to pay attention to steps and everything will work good. And finally, when you export your jar, don't forget to keep the Files_Folder in the same location to the jar, in order to find and use the needed files.
This question already has answers here:
Add image to JAR Java
(7 answers)
Closed 8 years ago.
I am trying to export my Java project using Eclipse's function but when I run it, it only shows the background, no external files. I used customized Checkboxes and Button, but they don't show up. Running it from Eclipse works perfect. This is the hierarchy for my Game:
.settings(folder)
bin(folder)
src(folder)
.classpath
.project
some .png files
This is how it looks in eclipse. I don't know what is with the red exclamation mark on Game.
These are the steps I took in creating the runnable JAR file:
I added my pictures to the Build Path (Skipping this step has the same effect)
I clicked Export - Runnable JAR file:
Then:
When I clicked finish, I had no warnings:
Why did you put all those images as referenced libraries? You should just put them in the src folder.
Any way, have you specified the main class when exporting the executable jar file?
Can you explain what happens when you try to execute the generated jar file?
These warnings may not be related to problem. But if you show them, it may be easy to check.
If I didn't get it wrong, Eclipse will only pack things in bin to the jar file. So you got two options:
Leave things as it is, but when deploying, put the images in the same folder with the jar file.
Put your images in src (so it would be copied to bin and hence packed) and change your way to access your image: get the URL with getClass().getResource() and read from the URL with something like Toolkit.getDefaultToolkit().getImage().
This question already has answers here:
How do I find the packages defined in a jar?
(5 answers)
Closed 8 years ago.
Is there any way to know the packages of a .jar file as I want to use "gtranslateapi-1.0" but not getting the package or class names in it.
I have also added it to my libraries in netbeans 8.0
You can see it here: https://code.google.com/p/java-google-translate-text-to-speech/downloads/list
please help, thanks in advance !!
jar is just a zip.so if you want to know what is packed into a jar file, you may unzip it (using either your favourite zip tool or jar itself e.g jar -t to list the contents). hint jar without args gives you a list of options
in netbeans you can easily see packages and classes .or you can rename .jar to .zip and open in compress program like winrar
in netbeans you can expand jar easily.add jar to libries and expand it .this is your jar file
This question already has an answer here:
How can I add class folders into Eclipse?
(1 answer)
Closed 7 years ago.
I have used the folllowing steps to add classes to my build path still i am geting errors as import not resolved.I had followed the following steps.
Select Create New Folder and name it
TpmWebUIClasses.
Click the Advanced >> button and
select the Link to folder in the
file system check box.
Browse for to the folder where you
have copied the classes
Make sure the selected folder is
listed and then click OK.
How can i resolve the error?
Right click your project > Properties > Java build path > Libraries > Add Class Folder
But it is much better to package these classes as a .jar and add it with Add JARs from the same screen. Another way is to make one project depend on another (whose classes are those in question).
Now, if you mean .java files rather than .class files, you just add a Source folder from the first tab on the Java build path screen. And be sure to make the distinction between .java and .class files.
There is a difference between folder and source folder. Right-click the folder and use Build Path/Use as Source Folder menu option.