I'm working on a java android project. this project requires to use specific commands.
these commands are all developed in c++/c but I've been given two files (.jar and .so) that are supposed to "turn them into" java, so I can use them in my java android project.
The thing is, what am I supposed to do with these 2 files?? I've read a lot of stuff (mostly about creating the .jar and .so, but I don't care about this step, for I already have the 2 files)
I tried to import the .jar (import external lib), I tried to add the .so via the static loading :
//static {
// System.loadLibrary("MySoFile");
// }
All I get is a stack overflow error or a problem with the DEX file...
Has anybody ever tried to do this??
I don't seem to get the point here...all I want to do is being able to use the commands in the .jar file.... ://
thanks in advance!!
Take a look at this answer about adding jar files. '.so' files can usually just be drag and dropped to the project.
All you need to do is make sure the jar is in your classpath and you can then access the classes within this jar. A jar is just an archive of classes, you don't need to load the library into memory or something similar.
You may want to read the answer to the question here How to use classes from .jar files?
Related
Sorry if the title doesn't say what I'm trying to do very accurately but I wasn't really sure how to describe it in one sentence. Basically I have a jar file with a java file inside it, and I want to edit the java file. I used 7zip to do so and it worked, letting me edit the code in the java file. I saved it and my new code shows up when I open the java file in netbeans. However, the new code isn't actually in effect, and my program is still using the old code. I don't know if this matters, but the java file is named Templates.java, located in a package called net.sf.dynamicreports.examples in a jar named dynamicreports-examples-5.0.0-sources.jar.
Thanks in advance for any help anyone can offer.
Edit: tried importing the jar into a new project and editing from there before putting it back into the original project, but had no luck (check comment chain for further details). Still have no idea how to fix this and would greatly appreciate any help
Your jar contains .class files and .java files.
When you create the jar, the .java files are compiled and .class files are created from them. You should have a Templates.class file that corresponds to Templates.java.
When you edited Templates.java, Templates.class was never recompiled. This class file is the one your program uses.
The appropriate way to change a jar file is unfortunately to regenerate the entire jar.
So, what you should do is open the code you used to create the jar in the first place, make your java changes there, and create a new jar.
You will need to do this even with the smallest changes.
I didn't make the jar myself unfortunately, I got it from somewhere else so I don't have the code used to make it, just the jar itself. What should I do?
Edit: I saw your comment that you did not make the jar in the first place. This isn't too big a problem since you do have the java source code. What you need to do is copy all the .java files in the jar and make a new jar with them. Or, simply use Eclipse or whatever your favorite java editor is to compile your Templates class, and copy the new Templates.class file it creates into the appropriate place in the old jar, overwriting the old one.
Where would I find the Templates.class file?
Edit 2: You find the class file in the bin folder of your project if you are using Eclipse. See this question: Find the .class file compiled by Eclipse or if you are using a different editor/compiler, search google for where it stores its .class files.
Disclaimer:
Before I get the standard "this has been asked 1000 times", let me say that yes, I know. I have read and read and read. Looked at JarJar and One-JAR but the problem is: I am self-taught with only a couple of months of experience under me and I am not familiar with Ant or Maven or anything other than vanilla Java. I use NetBeans as my compiler, just to add.
I have written an application for use at my job. It is just a small app that takes certain input and writes it to an Excel file. I downloaded jexcelapi (jxl.jar) and placed that appropriately. I have no trouble running the file inside of NetBeans or from within the dist/ folder after it is built. Therein lies the problem: if I move the app to, say, the Desktop, I get an error from the JVM saying "A Java Exception has occurred." I know that this is due to the fact that the main class is added to the .JAR automatically but to add another lib, I will have to make a "Class-path" statement within my Manifest. I tried that unsuccessfully. I have tried moving the actual jxl.jar file to my jdk folder and I tried calling the entire file path that points directly to the jxl.jar file into my Manifest. The closest I can get is building the .JAR in NetBeans and it adds the lib folder to the dist folder where the app .JAR is.
I want to distribute this app as just a single .JAR without having to send all the users a copy of the jexcelapi lib. It doesn't have to be a .JAR within a .JAR; it can be whatever way is easiest and simplest. As stated before, I am not familiar with Ant and One-Jar draws on that. I am still learning; can someone point me in the right direction with this? Thank you!
There is a better one for novice programmers.
Launch4j gives what you need, even wraps it to exe file. Yu don't need to know programming at all to use this.
OFC there are ANT task if you ant to automatise the Launch4j , but for that you must leant a bit about ANT :)
After hours of exhausting search, I found something that was incredibly short, sweet, and right to the point. You cannot mess it up. Here is the link.
I have started getting into game programming.
My question is, that when I am working with files, either parsing data, writing to files, etc. Should I be using relative path names, or absolute pathnames, or something else which is better. I've heard about using jar files, but I am not sure
1. how that works
2. if it is a good way to do it.
So when developing a game that will be cross platform, what is the best method for managing files that the program will need to read from and write to.
there are several ways in which you can ship your code as a product. the most common are
packaging everything in one executable jar file.
having a set of folders where you place all necessary resources.
minecraft, for example, is written in java and distributed as a single executable jar file that contains all necessary class files and resources. to run the game (assuming you have java installed) all you need to do is double-click the jar file.
read this short tutorial about how to add a main class to a jar file.
either way, always treat classes and resources in your code as if they're in your classpath. for example, if you have a my.properties file on the root of the source tree then load it by using 'my.properties'. if you put it under a 'conf' folder then use 'conf/my.properties'.
i think it is the safest way not to get lost.
are you using maven?
The jar file is a zip of all your compiled *.class files and your resources. You can safely load your resources and even default data FROM a jar if you package your program, but you can NOT safely write data back to the jar. This detail is answered in depth already at
How can an app use files inside the JAR for read and write?
For information on how to package a jar see
http://docs.oracle.com/javase/tutorial/deployment/jar/
I want to create one java application that will iterate an jar file and will give classes of that jar file.
I searched a lot but didn't get sufficient information.
I want java code that will open the jar file and will able to iterate that jar.
See:
java.util.jar.JarFile.entries()
http://docs.oracle.com/javase/6/docs/api/java/util/jar/JarFile.html#entries%28%29
I am trying to write a program in Java, which would collect a specified set of files from the physical location and place them in a jar in a certain directory.
I know I can use java.util.jar package for this. The package is great for sure, but I was wondering if there are any third party libraries that anyone at SO has used which they could recommend.
TL;DR: pick up files, create jar by placing them in pre-defined directories, all at run time in a java file.
P.S: I did not find any similar references to this question, but if there are then please refer me. Also, the title might be misleading, but I didn't find better words to explain my problem.
EDIT 1: I am not in anyway saying java.util.jar is bad or incomplete. All I am asking is if anyone has used any alternative solutions!
EDIT 2: I am trying to create the jar from inside the java program. The jar can be pretty big (~500mb) too. Trying to jar media files as well. So simply put, I pick up various files from certain locations on my drive and try to create a jar file by placing them in standard locations.
Thanks,
Ivar
Look at the java.util.zip package. Jars are just zip files with some extra stuff in 'em