A jar inside another jar in Android (Java) - java

I have a library project that uses a jar ("httpmime-4.1.3.jar"). I'd like to take the jar generated by that project and use it in other projects but when I use it in other projects and one class of the "httpmime-4.1.3.jar" is required the app crashes with a NoClassDefFoundError.
How can I solve that without having to add the "httpmime-4.1.3.jar" to all the projects reusing the library? Thanks!

You might consider using something like maven for dependency management. With maven, you specify the libraries that your library project depends on (httpmime). Then, any project that depends on your library will automatically recognize that it needs to download and put the httpmime jar in its classpath as well, and you don't have to worry about manually copying files around.
Edit: I just saw that you're specifically looking at android development. Here is a plugin with a nice getting started guide for using maven with android.

You have to add it to the classpath. You can't include it in another jar.

Related

Make an executable JAR from a maven project

I have a question about using Apache Maven: I built a very simple Maven-based project. This works fine so far.
Now I want to make an executable JAR file from my target file. The problem here seems to be that the dependencies (external libraries) are not packaged together with my app.
I've already googled and found the maven-assembly-plugin. That actually does exactly what I want, but seems to be somewhat inflexible, since the dependencies are not automatically resolved and I can not specify file filters, etc. (or only with much effort over assembly.xml).
What I really like is the solution of spring-boot-maven-plugin, so automatically determine all linked JAR files and put in a lib folder. Now my little project is not a Spring application, so Spring Boot might not be suitable for me, right?
So what would interest me: Is there a way to get a similarly structured and executable JAR archive as spring-boot-maven-plugin builds?
Just use Maven Shade Plugin. It packages your dependencies inside your jar and you can specify the Java packages to exclude

Is it possible to add a JAR file of a library project and use its resources in another project?

I am trying to add a JAR to libs for another project and then use resources from the JAR inside of that project but I am getting
java.lang.NoClassDefFoundError: com.xxxxx.dylib.R$drawable.
The JAR contents are:
com.xxxxx.dylib
res
res.layout
res.menu
res.values
When the library project is added as a dependency it works but when the JAR is used there is no R.java generated. I believe this is the problem. Is it possible to use resources from a jar within a project?
Resources cannot be packaged into jar. Pure java class that do not refer to resources can be packaged into jars.
You need to make the project that you need to refer to as a library project and then refer the same in your android project.
http://developer.android.com/tools/projects/index.html
If you want to use command line
http://developer.android.com/tools/projects/projects-cmdline.html
If your using eclipse follow the below link.
http://developer.android.com/tools/projects/projects-eclipse.html
You can right click on the project that you want to refer, goto properties. Choose Android and check Is Library.
Now to refer the library project in your android project.
Right click on your android project, goto properties, choose android, click add browse the library project and the same.
JAR files package only the Java code you have, and not the resources.
If you want to use the resources in your project, you will have to take the entire library project, mark it as a library and then add it to your main project as a whole.

How can I add a Play Framework 2.x module's managed code to Eclipse dependencies?

I made an eclipse project for my application using eclipsify. Then I added the code at appHome/target/scala-2.9.1/src_managed/main to the dependency list and everything works fine except for the code that calls modules. It seems I am missing some classes that belong to them. Where can I find them? What is the place where Play places the code generated for those modules?
I am currently running Play 2.0.2
Jose!
You should not change any code at target folders. This folders are generated automatically from your source folders.
So, just try to remove target folders from the project, and then use compile and eclipsify again.
Hope it would help.

Including jar in project. And including Android Library project

I want to include a jar library in my project, but the library is really large.
I am not using all of the classes from that library, so when I compile my project, will all the jar content will be put in compiled project or only files (classes, etc...) which I am using?
And same question about Android Library Project: If I include the Android Library Project in my project and I am not using all of lib resources, will the compiler put all of Lib Project resources in my project or only resources which I have used?
i apologize if i don't understand the question, but maybe what you're looking for is this:
Selectively include dependencies in JAR
so here's the plugin
https://github.com/nuttycom/sbt-proguard-plugin
sbt proguard looks like it will cut down the unnecessary classes, so that your project will not be "heavy"
Although you may not directly be using classes within the JAR, you could be indirectly using them. Therefore, it would probably be unsafe to remove these classes from the jar-- unless you're 100% sure they're not indirectly used by the classes you are using.

How to put eclipse jdt jar libraries in Java Build Path?

I'm trying to use eclipse jdt, and I tried to import related modules in java source file.
I have a bunch of errors as the jdt libraries are not in Java Build Path.
I tried to open Add Libary -> Plug-in Dependencies, but it doesn't have the jdt jar files.
I could use Add External JARs to point to all the jar files, but I don't think it's a good idea considering I have to do the same thing over and over again with new projects.
In this case, how to put eclipse jdt jar libraries in Java Build Path? The java.util.Collection is found automatically. I guess there might be some easy way to setup so that jdt jar files are found automatically.
Assuming your project is an eclipse plugin project you can add the jdt as a dependency and the jars will be automatically added to the plugin dependencies
Normally, I had to use eclipse plugin for using jdt for accessing the files in the workspace, and getting the jar files and such.
However, I found this solution to be very useful for using jdt/ask. The idea is to use string as an input to the jet, and import the related jars for using the jdt APIs.
http://www.programcreek.com/2011/01/a-complete-standalone-example-of-astparser/
I had to open Configure Build Path.
Then, I could select and import all the jar files that I downloaded from the site.
Now, I am ready to use the libraries.
In you Java Build Path screen, you notice two bottons Add Variable and Add Liberary below Add External Jars. Use those options and define a new variable or new user library; Once done, add the same in the project build path.
For newer project, you can simply reuse the variable/user library.
java.util.Collection is found as it is added as library in your build path(see first item in your screenshot). I am suggesting to do the same by introducing an User Library.

Categories

Resources