I have an android project in Eclipse which simply contains a "jni" directory containing c++ code which gets compiled into a native shared library, let's say libmod1.so. Then I have another android "front-end" project, which also contains a "jni" directory. I've set that project up to create a native shared library (let's say libwrapper.so) which I want to act as an interface to access libmod1.so, calling its functions etc.
I've seen a few questions about writing Android.mk files to express shared library dependencies but none I've seen refer to linking custom made libraries in separate Eclipse projects.
Rather than rely on a complicated make file though, if possible I'd like to instruct Eclipse to compile and copy the libmod1.so library into the "jni" directory of the "front-end" project whenever its built. From there I can compile it into the libwrapper.so library.
Does anyone know how to achieve this in Eclipse?
Or, can anyone suggest a better method of achieving the result I'm after? I'd prefer separate projects because I want to use the libmod1.so library with various "front-end" projects in future and so I want it to be in its own project.
Related
When there's no obvious compiled jars provided on a github project page, I've been downloading the clear code and kludging them into subdirectories in my codebase to make use of third party code (or, most of the time, just not using the code at all). I know that's not the right way to go about this; what is?
There's a popular post about importing github projects into Eclipse:
Importing a GitHub project into Eclipse
...and I've recently learned how to make my own projects depend on one another. Is this the practice, then, to fill up your workspace with projects you're not actually going to work on, so that you can declare dependencies? I remember making dependency references to web resources in the past (itch.io, maybe?) in some configuration, where I didn't have to go download the code. Is there a more elegant solution like that for github?
I'm using Eclipse, and the current library I'd like to use is: https://github.com/FasterXML/jackson
If you're trying to just use FasterXML, the jars are hosted on MvnRepository as well as a lot of other projects.
If a github project's artifact isn't available on MvnRepository or some other online repository you could potentially clone, build the war/jar file yourself, and then manually import it into your project instead of copy and pasting code directly into your project. This would give you access to the library.
A Java newbie here. I have created a small desktop application in IntelliJ IDEA 11.1. It consists of several java files with classes plus the main application file Main.java. I would like to make another application, which uses the same classes but a different Main file. I want to be able to change the classes source code from both projects. Therefore I'd like to have a structure like:
IdeaProjects\lib/myclasses\*.java (or similar with additional src if recommended)
IdeaProjects\project1\src\Main.java
IdeaProjects\project2\src\Main.java
How do I do it properly? I've read a lot about modules, libraries, jars and am just lost at the moment :(
I don't use IntelliJ so I can not help you specifically but You should create one project containing the shared resources and per program another project containing you Main files. Compile this first project into a jar file so you can use it as a library in the projects containing the main files.
In eclipse You can add other projects to your classPath. Maybe this is also possible in IntellyJ.
I have a Java project which is heavily used by all sorts of other Java and Android projects. The project contains some JAR libraries which shall be used by all projects, except for the Android one (in fact the Android project is a Android library project to be precise).
I marked the JARs as "export" in the Eclipse build path preferences of the Java project. However, the Android project shouldn't import these libraries (as they are Java libraries which make use of some classes which are not available on Android), but it shall import the rest of the code (which doesn't really use the libraries, but they are stored in there for convenience reasons and to ensure, that all other projects use the same library.
How can I prevent the JARs from being exported to the Android projects?
You can prevent all jars from being exported so that only the common project is a dependency for each project that needs it.
Then you can change the build path of each project to only include its necessary jars through the add jar.. dialog in build properties.
That's the easiest way.
A more extreme way would be to move to maven and then eclipse will only include the jars you specify in the pom - though that's a load of extra work for not much gain.
Alternatively, you could split the android specific code into a android-common separate project and then make your common project depend on it and export it - then your android project could rely on this android-common project instead of the existing common project.
There is a class, that compiles with the android platform and the jdk. Now, the idea is, to use that class in two projects, one is a android one and the other result in a java application.
So, I cretae a project with two modules, one for the android and one for the java solution. All works fine, with copy&paste the class-source between the two modules, but that is not very comfortable to use.
So, the question is, how it can be done without copy&paste. I would prefer a intellij solution, but I am willing to change to eclipse if needed.
Thanks for all answers.
FWIW, here's what I have working using NetBeans 7.1.1 ... it's possible that some of these steps aren't needed, but after a couple of days experimenting this seems to work.
Create a "Shared1" Java Library containing the shared classes & their source code
Add the "Shared1" library to the desktop Java project
Create a "Shared" Android project... in Properties, tick "Is Library" and set up a Custom location "../Shared1.dist"
Add the "Shared" project to the Libraries in the Android application project
Add "Shared1" as a JAR library (Custom location "../Shared1.dist") in the Android application project
The classes in the "Shared1" project are now usable in both the desktop environment and the Android environment.
BEWARE!!!! Using java.awt classes in the "Shared" library classes doesn't generate any compiler warnings, but causes the Android application to crash. Subsequent runs also crash, even if the java.awt reference has been removed and Clean & Build done on everything!!!
Create a MyLibrary project containing the shared class, package it as a jar (MyLibrary.jar), and add this jar as a library of the Java and Android projects.
Since you say the class is "common", that implies it doesn't use any Android-specific classes. In this case, you can just distribute the common code as a JAR library to the java and Android projects.
Unfortunately I do not really understand what does it mean project with 2 modules.
Typical solution for this problem is 3 projects:
android project
other project
shared (utility) project
Projects 1 and 2 depend on project 3.
If you are using maven it is pretty simple to do: you just have to add appropriate dependency tag. For example if your utility project's artifact is "com.mycompany.util" add definition like the following to pom.xml of your dependent projects:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>util</artifactId>
<version>1.0</version>
</dependency>
Let's say you create a new project, and want it to make use of some 3rd party library, say, widget.jar. Where do you add this JAR:
File >> Project Properties >> Libraries >> Compile-Time Libraries; or
File >> Project Properties >> Libraries >> Run-Time Libraries; or
Tools >> Libraries (Library Manager) >> Library Classpath; or
Tools >> Java Platforms (Java Platform Manager)
All of these dialogs seem to do the same thing but I'm sure they all have their proper usages. Can't find a good "best practices" article online and the NetBeans Help Contents dialog isn't helping with this either.
Right click 'libraries' in the project list, then click add.
You want to add libraries to your project and in doing so you have two options as you yourself identified:
Compile-time libraries are libraries which is needed to compile your application. They are not included when your application is assembled (e.g., into a war-file). Libraries of this kind must be provided by the container running your project.
This is useful in situation when
you want to vary API and implementation, or when the library is supplied by the container (which is typically the case with javax.servlet which is required to compile but provided by the application server, e.g., Apache Tomcat).
Run-time libraries are libraries which is needed both for compilation and when running your project. This is probably what you want in most cases. If for instance your project is packaged into a war/ear, then these libraries will be included in the package.
As for the other alernatives you have either global libraries using Library Manageror jdk libraries. The latter is simply your regular java libraries, while the former is just a way for your to store a set of libraries under a common name. For all your future projects, instead of manually assigning the libraries you can simply select to import them from your Library Manager.
If your project's source code has import statements that reference classes that are in widget.jar, you should add the jar to your projects Compile-time Libraries. (The jar widget.jar will automatically be added to your project's Run-time Libraries). That corresponds to (1).
If your source code has imports for classes in some other jar and the source code for those classes has import statements that reference classes in widget.jar, you should add widget.jar to the Run-time libraries list. That corresponds to (2).
You can add the jars directly to the Libraries list in the project properties. You can also create a Library that contains the jar file and then include that Library in the Compile-time or Run-time Libraries list.
If you create a NetBeans Library for widget.jar, you can also associate source code for the jar's content and Javadoc for the APIs defined in widget.jar. This additional information about widget.jar will be used by NetBeans as you debug code. It will also be used to provide addition information when you use code completion in the editor.
You should avoid using Tools >> Java Platform to add a jar to a project. That dialog allows you to modify the classpath that is used to compile and run all projects that use the Java Platform that you create. That may be useful at times but hides your project's dependency on widget.jar almost completely.
Project Files Services Tabls
go files tabs
drag drop file to libs files hover.
return project tabs and what are you see :)