This is a completely newbie question from a Java programmer trying to learn Erlang. What's the equivalent of a Java JAR file in Erlang by which 3'rd party libraries can be included in an Erlang application?
The other day I made a copy of the mochijson2.erl in my project and it worked, but I am wondering if there's a better/more formal way of discovering and including libraries in the Erlang world.
If you're familiar with Maven (or its siblings), the Erlang analogue is Rebar.
You could create a rebar.config (similar to a POM file) with the contents
{deps, [
{mochiweb, "2.9.0", {git, "https://github.com/mochi/mochiweb.git", {tag, "v2.9.0"}}}
]}.
Then rebar get-deps && rebar compile will fetch mochiweb (and any dependencies it declares), build the dependencies, and build your own code.
Related
I am trying to use a native library on an ARM based Mac, i.e. an M1 processor. There are several JVMs available for that architecture, for example Azul or Liberica. Both come with a JavaNativeFoundation.framework dynamic library, which is necessary to use any JNI code. However, the framework does not have a Versions folder that contains the major version of the framework (like A). Instead, the library is just contained in the top level folder:
/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/JavaNativeFoundation.framework
/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/JavaNativeFoundation.framework/_CodeSignature
/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/JavaNativeFoundation.framework/_CodeSignature/CodeResources
/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/JavaNativeFoundation.framework/JavaNativeFoundation
/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/JavaNativeFoundation.framework/Resources
/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/JavaNativeFoundation.framework/Resources/Info.plist
Trying to run my program I get
[java] AquaNativeSupport: Unable to load library libvaqua.dylib: /private/var/folders/tg/06858t0j3w10js_5hb3k5frw0000gn/T/libvaqua4883847212092667097.dylib: dlopen(/private/var/folders/tg/06858t0j3w10js_5hb3k5frw0000gn/T/libvaqua4883847212092667097.dylib, 0x0001): Library not loaded: #rpath/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation
[java] Referenced from: /private/var/folders/tg/06858t0j3w10js_5hb3k5frw0000gn/T/libvaqua4883847212092667097.dylib
[java] Reason: tried: '/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/./JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation' (no such file),
'/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/../JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation' (no such file),
'/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/bin/./JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation' (no such file),
'/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/bin/../lib/JavaNativeFoundation.framework/Versions/A/Java
It looks like the output is incomplete, but anyway: You can see that java is trying to load the framework from a Versions/A/ subfolder of the framework, which does not exist anywhere.
If I create that subfolder and create a softlink to the existing binary JavaNativeFoundation in it, then the application loads the JNI code just fine.
Given that situation I have two questions:
Why are the Frameworks in both Azul/zulu and Liberica missing the Versions structure?
Is there a way to work around that problem by loading the Framework in a different way? Some "dontusemajorversion" flag?
Thank you for your help.
I started a small proof of concept exercise to make us of the Toothpick DI framework with an existing Gradle based Java project. I have read quite a few claims that you can use Toothpick with Java (meaning the JRE, OpenJDK, JDK or JSE - No Android) ... However, every example I've been able to check/work through has at some point a dependency on Android in some way, shape or configuration.
With the most (partially) successful effort so far has been to use an experimental, throw-away Android mocking package to have my Java project at least compile without error. That said it comes-up blank on resolving any should-be generated dependencies, such as the:
generated MemberInjectorRegistry
generated FactoryRegistry
The Toothpick sample project itself and the simpler of the available examples all use an Android configuration and often as not dependencies on other Android specifics.
update Two
I took direction to the Toothpick sample project, a Java project
https://github.com/stephanenicolas/toothpick/tree/master/toothpick-sample
The Tootpick wiki and the sample project use the Java compile option:
compileJava {
options.annotationProcessorPath = configurations.annotationProcessor
options.compilerArgs = ['-Atoothpick_registry_package_name=experiments.toothpick',]
}
That gave me a warning that turned-out to be a mismatch in Gradle and plugins. And I needed a new build with --refresh-dependencies (hint: make sure you compile the TestsPackages).
After fixing that the sample compiles and passes the Unit Tests. The generated files are under build/generated and I managed to encourage Netbeans to find them with this:
sourceSets {
generated {
java {
srcDirs = [ 'build/generated/source/apt/main' ];
}
}
}
Sadly Netbeans continues to put little red-lines under the generated symbols. At least it runs. Netbeans support could be better.
My earlier experiment looked on the Toothpick Smoothie which is an Android example. Kind of interesting as an intellectual exercise ...
Smoothie sample
That build.gradle file relies on Android. So I tried mock substitutes for missing components. The project compiles but can't find (any) generated code.
I would have considered by now that there might be at least ONE successful Java JRE/JDK Toothpick project example 'out there'.
update One
I decided to tackle this from the other end and look to the common Java annotation processing examples. This works as far as I got, with Gradle v4.7 (and also I think v4.6).
In your (sub-)project build.gradle ...
plugins {
id "net.ltgt.apt" version "0.15"
}
:
dependencies {
annotationProcessor (
dep_toothpickCompiler
)
:
}
The dep_toothpickCompiler is defined earlier as:
// Annotation Processor
dep_toothpickCompiler = "com.github.stephanenicolas.toothpick:toothpick-compiler:${ver_toothpick}"
results ...
This step at least managed to create a
build/generated folder
Unfortunately no generated output so far. There is light at the end of the tunnel, I'm sure. I'll post updates here if/as I get closer to a solution.
learning examples (GitHub)
I've identified some 'reliable' Toothpick examples. So far they want Android in there some place. Either as Android targeted modules or using related dependencies.
https://github.com/davidbcn/ToothpickWorkshop
https://github.com/WarrenFaith/Toothpick-Sample
https://github.com/wongcain/okuki
https://github.com/search?l=Java&q=toothpick&type=Repositories
Given (or assuming) that a pure Java / Toothpick project can build, debug and run on the desktop or from the command line; it doesn't seem to be a popular choice as far as my googling went ...
--
You should look at the TP sample, it is pure Java.
https://github.com/stephanenicolas/toothpick/tree/master/toothpick-sample
Smoothie is actually the android specific part of TP.
I am stuck at importing a library which is originally written in C++, but has native binding for Java. Here is the library https://github.com/NationalAssociationOfRealtors/libRETS, and I was able to build it through the doc in doc/build, but what after that? I see some makefiles in project/build/ and I want to import this library in Java. Any help will be really appreciated as I cannot find anything in the documentation, all I know is there are some makefiles and the description claims that this library has native bindings for other languages.
Watch the output of ./configure carefully and make sure the build is configured to create the SWIG components (namely, for Java.)
Option summary:
Use ccache .................: no
Use dependency checking ....: no
Use -fPIC...................: yes
Use shared dependencies.....: yes
Compile type................: Normal
Compile examples............: no
Compile SQL compiler........: no
Compile SWIG bindings.......: no <-------- should say yes
With DotNet...............: no
With Java.................: no <--------- me too
With PERL.................: no
With PHP..................: no
With Python 2.............: no
With Python 3.............: no
With Ruby.................: no
With Node.js..............: no
Enable Maintainer Docs......: no
I tried it and a fairly recent version of SWIG was required -- more recent than were in my package manager. Without that, the SWIG bindings don't get built and there's no Java.
However, once you do get that build, it should be a fairly straightforward endeavor of calling into a jar file, as with any other Java project. Who knows, the build might even generate Javadoc for you so you have some idea of what to call.
I've made an API Wrapper with Android Studio, mainly to be used with Android Apps. I would like to make a .JAR file out of it, so that Java applications may also use it.
Is that possible? If so, how?
I've looked at how to make .JAR files out of Android Pojects, but not much came out of it. I also don't understand how is the Java application going to handle the Android net import, for example.
you can add a "jar" task to your lib-s build.gradle to generate a jar like this:
apply plugin: 'android-library'
android {
...
}
task jar(type: Jar) {
from android.sourceSets.main.java
}
dependencies {
...
}
You have to keep in mind that ordinary non-android java apps cannot use classes that directly or inderectly depend on namespaces android.*
I prefer to create an ordinary non android-dependant java-library-subproject in android-studio that generates a jar file and that can be consumed by your android-app.
One additional benefit of seperation non-android-lib from android-app is that you can write junit-4 tests for them.
Ordinary android-junit tests depend on junit3. Executing android-junit-tests requires to launch the emulator/android-device which is timeconsuming.
An ordinary non-android-junit-test runs much faster because it does not need emulator/android-device
I've just started using the PythonInterpreter from within my Java classes, and it works great! However, if I try to include python modules (re, HTMLParser, etc.), I'm receiving the following exception (for re):
Exception in thread "main" Traceback (innermost last):
File "", line 1, in ?
ImportError: no module named re
How could I make the classes from the jython jar "see" the modules python has available?
You embed jython and you will use some Python-Modules somewere:
if you want to set the path (sys.path) in your Java-Code :
public void init() {
interp = new PythonInterpreter(null, new PySystemState());
PySystemState sys = Py.getSystemState();
sys.path.append(new PyString(rootPath));
sys.path.append(new PyString(modulesDir));
}
Py is in org.python.core.
rootPath and modulesDir is where YOU want !
let rootPath point where you located the standard-jython-lib
Have a look at src/org/python/util/PyServlet.java in the Jython-Source-Code for example
According to the FAQ:
4.1 What parts of the Python library are supported?
The good news is that Jython now supports a large majority of the standard Python library. The bad news is that this has moved so rapidly, it's hard to keep the documentation up to date.
Built-in modules (e.g. those that are written in C for CPython) are a different story. These would have to be ported to Java, or implemented with a JNI bridge in order to be used by Jython. Some built-in modules have been ported to JPython, most notably cStringIO, cPickle, struct, and binascii. It is unlikely that JNI modules will be included in Jython proper though.
If you want to use a standard Python module, just try importing it. If that works, you're probably all set. You can also do a dir() on the modules to check the list of functions it implements.
If there is some standard Python module that you have a real need for that doesn't work with Jython yet, please send us mail.
In other words, you can directly use Python modules from Jython, unless you're trying to use built-in modules, in which case you're stuck with whatever has been ported to Jython.
Check your jython sys.path . Make sure that the library you want to load are in this path.
Look at jython faq for more details.
You can refer here for the solution Importing python modules in jython
Download ez_setup.py from here http://peak.telecommunity.com/dist/ez_setup.py
Then run jython ez_setup.py <any module name>.
Running it on any folder path doesn't matter.
I could install pymysql with it, no problem.