Create Apklib for building with maven - java

I have Android project A which refers Android library project B, Building Project A on eclipse works fine. But my app using some system API so I thought to build using maven. I am not getting how to include Project B in Project A on maven.
(basically proj B has both source and resource)
Basically I generated B.jar and edited pom file
<dependency>
<groupId>com.me.example</groupId>
<artifactId>myId</artifactId>
<version>2.4.1</version>
<type>lib</type>
</dependency>
then I am able to build A.apk but when I launch A.apk application, its crashing. Because project B has some resources and when I generate B.jar it has only class files and don't have resources. And also I tried to generate B.apk and included included in maven and I couldn't able to build A.apk.
How can I solve this.

First I built B.apklib then I included it in A project as dependency and now I am able to build A.apk
B.pom contains
<groupId>com.mer</groupId>
<artifactId>me</artifactId>
<version>1.4.3</version>
<packaging>apklib</packaging>
<name>I_am</name>
<dependencies>
.......
</dependencies>

Related

Why maven is not finding a package located in another module/project?

I'm trying to compile a multi-module maven project. I have problems to compile a new module I added. This problem arises because the new module is trying to import a pair of packages which exist in another module.
This is the pom.xml of the new module:
Here is the view in the eclipse's project explorer, where i highlighted the 2 packages I'm importing from the class ServicioJMS of the new module:
And here's the error showed in the command line after doing a mvn clean package
As you can see below I added the module in the parent pom.xml:
So, I don't know what I'm doing wrong here ¿Any ideas?
NOTE: Eclipse has no problem resolving the dependencies related to the discussed imports.
I had a similar problem. Go to the library on which you are depending (under your ~/.m2/repository directory or in the ./target directory of the library) and find the compiled library jar. Use jar -tf to list it and check that the missing classes are listed directly in the jar.
If you are using the spring boot maven plugin or similar in the library on which you are depending then it constructs a jar with a radically different structure and the classes, while being in there, will be hidden within the structure rather than being directly in the jar by name. Eclipse understands this, but the spring boot loader won't unpack the spring boot maven plugin structure of a library within a dependency, it will only do that for the runnable jar being executed.
If this is true for you then you can remove the offending build plugin from the pom of your library making it just a library, not a runnable spring boot jar.
A few things:
1) Don't put a version or group if you have a parent, let them be picked up from the parent.
2) When importing a dependency from a module under the same parent use ${project.version}
here's an example:
<parent>
<artifactId>parent</artifactId>
<groupId>com.essexboy</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<dependencies>
<dependency>
<groupId>com.essexboy</groupId>
<artifactId>library</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Use install instead of package because IntegradorTransformador artifact (jar) was created but not exists in m2 repository and IntegradorTransformadorReproceso project can't found the artifact
mvn clean install

Maven project architecture

I am trying to add the locally created project which contains JARs added using java build path to my maven project as dependency and the JARs used in the dependency project are also be useful in the main project. how to deal in this scenario if I don't want to convert my dependency project to maven?
You have different possibilities:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>2.53.1</version>
<scope>system</scope>
<systemPath>
C:/.../your-jar.jar
</systemPath>
</dependency>
or you can install it in your local .m2 repo
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
This doesn't force you in any way to convert your project into a maven project, but let you reuse the jar you already have.
This is similar like Maven multimodule project. In that all the submodules gets added to the root project as a jar after successful compile. In your case try covert the project into jar and copy the same jar file to the lib folder of parent project.

How to set up Maven in an Android Project under Eclipse

Basically I have been fiddling around to get an existing android project to work with maven under eclipse luna.
So here is the way the project was set up to begin with.
The project is a simple android project, which references two external .jars (those are in the libs folder and referenced via add external jars) and then also three additional selfmade libraries which are simple android project but set up to be libraries (via the Is Library checkbox in the Android project properties).
So like this:
Workspace
MainProject -> Android Project
libs
lib1.jar -> referenced in the build path via the add external jars
lib2.jar -> referenced in the build path via the add external jars
SelfMadeLib1 -> Android Project -> set up to be a library and is also referenced in the MainProject via the Add which is available in the Android part of the project properties
SelfMadeLib2 -> Android Project -> set up to be a library and is also referenced in the MainProject via the Add which is available in the Android part of the project properties
SelfMadeLib3 -> Android Project -> set up to be a library and is also referenced in the MainProject via the Add which is available in the Android part of the project properties
Well this was the way I always did it, but since there is maven I figured I could get around this and use maven. So I went a head and removed the self made libs, created a new workspace specifically for them.
Then I added the projects via Import... -> Existing Android Code into Workspace. After that I simply used the Maven Android plugin to convert them via Configure -> Convert To Maven Project. After fixing the referenced Java SDK (set it up to use the old 1.6_45 on my system) I could create the projects via maven and install them in my repo, so no problem there.
Next thing was to configure the existing MainProject, but this did not work. I was able to convert the project into a maven project as well (same way as above with the selfmade libs) and also add the selfmade libs via maven. They are also shown in the Maven Dependencies and I also checked that those dependencies should be included in the project (via Order and Export tab in the Java Build Path of the project properties)
However when I try to debug the whole thing it does not work because of a ClassNotFoundException which gets thrown as soon as I start the app.
So next thing I did was simply to reused the original android project and add the libs the old way (via add external jars) and this works ofc. After analysing the project I simply figured that the maven project does not have the libs because they are not shown under Android Private Libraries in the Java Build Path of the project properties.
So my question is, was anybody able to get android project to work with maven and if so how ?
EDIT:
as requested here is the pom file as well
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyanid.android.dota2.soundboard</groupId>
<artifactId>xyanid.android.dota2.soundboard</artifactId>
<version>1.3.0.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>de.xyanid.android.database</groupId>
<artifactId>xyanid.android.database</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>de.xyanid.android.gui</groupId>
<artifactId>xyanid.android.gui</artifactId>
<version>1.0.0.0</version>
</dependency>
</dependencies>
</project>
note that de.xyanid.android.database als contains ormlite.core, ormlite-android as well as another selfmade lib. I also tried to include thos as well but that did not change anything.

Rebuild java project from compiled one

There is a java project built with Maven. I have project sources, need to improve something and then rebuild the project.
The problem is one of Maven dependencies is now lost (seems like it was only in developer's local repo). But there is a compiled project (.ear). I suppose it has code from that Maven dependency.
Is there a way to build a project using old project's compiled files?
Extract the required jar from old ear, and in new pom add that jar as dependency,
<dependency>
<groupId>GroupId</groupId>
<artifactId>ArtifactId</artifactId>
<version>VersionNo</version>
<scope>system</scope>
<systemPath>path/to/the/jar</systemPath>
</dependency>
You can use the compiled jar's and put them into library folder and rebuild path.

Maven Java project in eclipse and mongodb libraries

I have a Maven project in Java. I am new to all of these concepts. I created a Restful project which works well with a file repository. But I want to change that to a mongo repository.
So I added my repository class, then I need to add the mongo libraries. I right click on the project and select Maven --> Update, but the libraries are not being downloaded. So I add them myself via Project Build path and this makes my project to compile.
However at runtime I get the exception of classNotFound for mongo classes.
I read some posts and added these line to pom.xml:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>1.3</version>
</dependency>
Still not compiling. How should I add the libraries in a way that it compiles and also at runtime my program can find those classes?
Where did you get 1.3 for a version? The latest is 2.12.1.

Categories

Resources