I'm somewhat new to java, and very new to maven. I might use some terminology imperfectly.
As I develop my project that I'm using use maven to build, as I've needed classes that aren't part of the core java language I've added an appropriate <dependency>
section to my pom.xml
(usually copied from mvnbrowser.com without my really understanding it very well), and I've been able to use the classes I want. Works great.
Now I've encountered a java class that I want to use that is apparently not available in a maven artifact. It's com.android.sdklib.build.ApkBuilder
which is distributed with the android SDK. I wrote a standalone java program to get my code working; I compile it with javac
and not with maven, and that works fine. For that, I put the jar file that contains the class I want, sdklib.jar
, into my jre/lib/ext
directory (/usr/local/jdk1.6.0/jre/lib/ext
on a FreeBSD machine), and my import com.android.sdklib.build.ApkBuilder
line compiles fine and I can refer to ApkBuilder
and use it with no problems.
Now, when I copied my working code into my maven project, and tried to build with mvn project
, I get package com.android.sdklib.build does not exist
errors on the import line, and cannot find symbol: class ApkBuilder
errors where I refer to ApkBuilder
.
Looking around the net, I found android-maven-plugin
here: http://code.google.com/p/maven-android-plugin/. It referred me to maven-android-sdk-deployer
here: https://github.com/mosabua/maven-android-sdk-deployer. These leads sounded promising at first, but as far as I can tell, their purpose is for developing android applications using maven, which is not what I'm trying to do. I just want my java program to manipulate android apk
files, but my java program itself is not to be run on an android device. Also, the android SDK is made to work with linux, not FreeBSD which I'm using, so I cannot follow the installation instructions for maven-android-sdk-deployer
. I also found an artifact called maven-apkbuilder-plugin
but that also seems to be for the purpose of creating android applications and I didn't see documentation for it. So I haven't pursued these leads.
It seems the easiest thing would be just to get the compiler to look in my jre/lib/ext
folder for the sdklib.jar
file when running mvn package
. But maybe that's not the way to go. Or maybe there's a simple change I can make to my pom.xml
that will cause the compiler to find sdklib.jar
. I looked at the pom documentation at http://maven.apache.org/pom.html#Build_Settings, but didn't see a way to do that. Anyway, I'm sure there's at least one solution; I just don't know it (yet).
What are my options? What's the best way to use the ApkBuilder
class in my maven-built project? What should I have read that would have enabled me to answer this question myself? Thanks!!
If you're just trying to reference the jar, the simplest solution might be to add the jar to your local repository manually. See here for details.
Nutshell:
mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=jar
You may use whatever you want for the group-id
, artifact-id
, and version
, but they should be something resembling what you'd expect if it was available in the repo.
Since you're not actually creating an Android project, this may be sufficient.
Here's how I would have asked the question.
How can I use a library not available from a Maven repository in my Maven build?
(Coincidentally, that, and shorter variations of that, should bring up the links you "should" have read, to answer your last question :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With