Hi i am developing a sdk in java, in the sdk the users will provide the node modules names. Is there any way to download those npm packages in java with all its dependencies without forcing the end user to install npm?
You can start by studying npm's registry api. You can look for packages by appending the package name at the end like this http://registry.npmjs.org/express and you just have to parse the returned json and look for the latest tarball urls (if you're looking for the latest distribution, else you can code your plugin to look for specific versions). And then look for the dependencies entries and do the same for them (access the api and download the tarballs). You can actually find more info at their docs.
I recommend to take a look at this java library: https://github.com/OrienteerBAP/JNPM
Along with native Java API to work with NPM it also provides Command Line Interface, transparent CDN-like access to NPM resources via Servlet for example and maven plugin to get NPM resources and pack within your java library (lightweight replacement of WebJars)
Related
I have the last Ubuntu version on my computer and i tried many times to install the library Libsvm,following the instructions at this link: https://www.php.net/manual/en/svm.requirements.php.
The link is for installing the library in php,but to add the php extensions,the library need first to be installed in java.
I hadn't any problems with this commands,(obviously,i typed all the commands for the latest version of the library,3.24)but when comes the moment to compile the test file.java with the javac command,the compiler doesn't recognise my SVM class...
Here I paste the code in the java file.
svm_predict svm = new svm_predict();
And I also tried this :
LibSVM svm = new LibSVM();
I'm really desperate,please give me a hint!
In order to use libsvm within your Java project, you need to add the corresponding JAR file (libsvm.jar) to your classpath.
I suggest to use an IDE (such as Eclipse or IntelliJ) for Java programming in order to manage the libraries in your classpath.
If you prefer to stay with command-line compiling via javac, you can use the parameter -cp to add libraries to your classpath. You can find details for it in this post on Stackoverflow.
I'm writing some code that uses the Subversion (SVN) Java bindings (JavaHL) directly (where JavaHL comprises native libraries and a thin Java wrapper). On Linux (Ubuntu 12.04) this is no problem: package libsvn-java installs the native libraries and \usr\share\java\svn-javahl.jar, so i just reference the latter and away I go.
On Windows, I know of no such clean packaging of the pair (JAR + native libraries) together. I was aware that SlikSVN contains a JavaHL implementation, but installing that seems only to install the native libraries (which it does put on the PATH). Is there anything that gives a clean package of the two? (If SlikSVN does package the JAR, it's in no place I expect, and a search of the whole drive finds nothing...)
As a workaround, I built the JAR file manually (details below which may be useful for people). But it seems that the 'match' of Java wrapper and native libraries is very precise: when I built a JAR from later SVN source code (instead of that matching my exact SlikSVN SVN version) as a test, I got fatal errors in the native code (EXCEPTION_ACCESS_VIOLATION). Perhaps I was unlucky but, if it is pretty sensitive, I'll need to provide a JAR library for every potential version of SlikSVN (and thus SVN) that users might install (or restrict their SlikSVN choices, or have some prone-to-error auto-build process which would need them to install a JDK). All bad options :-(
Manual Workaround (Bad!)
I had SlikSVN 1.8.10: svn --version reports version 1.8.10-SlikSvn-1.8.10-X64.
So I got the Java wrapper source from the tagged SVN release. (You can also get it from the
main site's source downloads.)
svn export http://svn.apache.org/repos/asf/subversion/tags/1.8.10/subversion/bindings/javahl/src
Compiling this (there are no dependencies) into a JAR, and using that, worked fine with the SlikSVN native libraries.
P.S. I know that I could use SVNKit to avoid having to do this, but I'm doing this precisely so as not to rely on SVNKit for licensing reasons (plus the JavaHL API is fine and reasonably high-level anyway, and there are other reasons to prefer using the 'official' native JavaHL implementation).
The WANdisco binaries should have JavaHL in them.
http://www.wandisco.com/subversion/download
Been a while since I used them myself (don't typically use Windows). But WANdisco has tools that depend on JavaHL so I can't imagine the Windows binaries are missing JavaHL.
[Question author edit to complete detail]
You need to install the (Windows) Subversion client (not SmartSVN), and make sure you check the box to add it to the Windows PATH. This stores the 'paired' JAR in the install directory (along with the native libraries). However, WANDisco only provide a 32-bit install (see this forum post) so this won't work on 64-bit Windows. In addition, the JAR only includes the Apache versions of the API, which were added for Subversion 1.7. If you're using the legacy org.tigris.subversion.javahl package API for compatibility with pre-1.7 SVN clients, you still need to build the JAR manually.
In the context of Java 8 and Nashorn I see two projects being regularly mentioned.
Avatar.js and Project Avatar
What is the relation of these projects?
Avatar.js has very little documentation. As far as I gathered it offers the possibility to execute node applications on the JVM.
Project Avatar seems to build on Avatar.js. However the scope seems to be to provide an alternative Web-Framework for Java EE 7. Is it also possible to execute node programs (like i.e. grunt) with Project Avatar?
Update: Project Avatar was officially halted 2015-02-12.
Avatar.js is the open-source version of what was informally called 'node.jar' (See this post from the avatar-js mailing list). In other words, it is a NodeJS-compatible API, running on Nashorn. Project Avatar appears to be Oracle's answer to the NodeJS API, offering an alternative platform which also provides compatibility with the NodeJS API and ecosystem via Avatar.js.
Therefore it is not that Project Avatar is built on Avatar.js, but rather that "Avatar.js is one component of Project Avatar. Nashorn is the JavaScript engine used to run both." (again, from this post).
The Avatar.js homepage currently has a list of modules known to run, including "grunt". It would appear that Project Avatar currently includes a build of Avatar.js as "avatar-js.jar", as found in the current latest commit, though it is 4 months old. So I think the answer is that yes, the current build of Project Avatar will allow you to run Node-compatible modules.
As you've pointed out, both of these initiatives lack documentation, and are in their infancy. Time and community engagement will show where they fit best.
Indeed there is Avatar.js included in Project Avatar.
By looking at the Maven POM files of Project Avatar, I discovered that there is a binary distribution of Avatar.js available through the java.net Maven repository.
Based on this discovery I wrote a blog post how to run simple Node.js apps with Avatar.js here:
Running Node.js applications on the JVM with Nashorn and Java 8
Steps for OSX repeated here:
Download avatar-js.jar from the java.net Maven Repo. Current version
is here:
https://maven.java.net/content/repositories/public/com/oracle/avatar-js/0.10.25-SNAPSHOT/
Example file: avatar-js-0.10.25-20140313.063039-43.jar
Download the native library avatar-js.dylib from the java.net Maven
Repo. Current version is here:
https://maven.java.net/content/repositories/public/com/oracle/libavatar-js-macosx-x64/0.10.25-SNAPSHOT/
Example file:libavatar-js-macosx-x64-0.10.25-20140312.062209-35.dylib
For Linux
you would download the corresponding .so file from ../libavatar-js-linux-x64/0.10.25-SNAPSHOT/
For Windows you would
download the corresponding .dll file from
../libavatar-js-win-x64/0.10.25-SNAPSHOT/
Rename the native library to avatar-js.dylib and rename the jar to
avatar-js.jar and put both in a directory called dist.
Create a simple Node.js app in the a file called app.js.
Run the command: java -Djava.library.path=dist -jar dist/avatar-js.jar app.js
Project Avatar does indeed layer on top of Avatar.js; the code is integrated into our build using Maven. (The jar you found, Johann, was old because we no longer use it -- I just nuked it, thanks).
And yes, we're aware that our docs need more work. For now, we are focussing on fleshing out the server-side JavaScript framework. This services layer provides a runtime tuned for easily creating REST, WebSocket and Server-Sent Event endpoints.
I'd be very grateful if someone could provide me the basic steps to install the Play2War Plugin. Like where to put the plugin files?, and which files?
I'm pretty new with Play Framework (Java, I'm not a Scala developer, ...yet), just created my first application, and want to deploy it on my server, with is a CentOS with Tomcat/ Glassfish installed, but unfortunately I found out that the 2.x version didn't have the built in war command anymore. I scoured the documentation and found the links Configuration, Usage and Deployment, but what I want to know are the steps until get there.
I started looking for sbt building tool ('cause Play2War Plugin uses it), until I realize that Play Framework 2.1.1. already have it installed (at least that is what I believe. See: *PLAY_HOME/framework/sbt/sbt-launch.jar* and *PLAY_HOME/framework/build*). Am I correct?
Thanks in advance,
As Play 2.1.1 already has SBT its as simple as doing the following:
Within plugins.sbt add:
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.0")
Then within the Build.scala file add:
import com.github.play2war.plugin._
...
val main = play.Project(appName, appVersion, appDependencies)
.settings(Play2WarPlugin.play2WarSettings: _*)
.settings(Play2WarKeys.servletVersion := "X.X")
The X.X needs to be changed to the required Java Servlet version (usually 3.0 or 2.5 depending on your container)
If you have a working play application, you are already using SBT tools to build. Yes, SBT comes with play.
The play2war plugin tutorial provides a step-by-step instruction. Simply follow the tutorial, you should be fine.
To answer your question, where to put the plugin file?
As the tutorial suggests, you need to modify files like APP_HOME/project/plugins.sbt, APP_HOME/project/Build.scala. You should already have these files, you simply need to add those lines to these existing files.
If you have a specific problem, please provide the error message.
I've been reading up on PhoneGap and really like it. I'd like to see if I can use it with GWT to write Java apps that deploy to many different platforms (web, mobile web, android, iphone, winphone, etc.).
It looks like the PhoneGap SDK comes with different versions of cordova.js for each native platform you want to support. So it looks like the Ant build will have to somehow package the GWT-generated JavaScript to the correct version of cordova.js:
3098DJU39I4F9IF9.html + cordova-android.js
3098DJU39I4F9IF9.html + cordova-iphone.js
3098DJU39I4F9IF9.html + cordova-windows-phone.js
I'm generalizing here, and I know those aren't the correct file names (although, obviously, 3098DJU39I4F9IF9.html is the GWT-generated code).
But then something has to kick-off PhoneGap's ability to take each of those pairings and produce the correct packaged container: an APK, IPA or XAP for each platform respectively.
So I first ask: how does a PhoneGap developer normally go from 3098DJU39I4F9IF9.html + cordova-android.js to having a myapp-android.apk, or from 3098DJU39I4F9IF9.html + cordova-iphone.js to having a myapp-iphone.ipa? Does the PhoneGap SDK have a command-line tool that does this?
Once I understand that much, I'm trying to figure out how to automate this packaging/binding process from an Ant build. Are there any known Ant tasks that already do this? Or do I need to kick off a shell from inside Ant and just run the shell commands? Thanks in advance!
#rooftop is right, you have to build the native app using native SDK even if you are using Phonegap. The benefit lies in creating the UI and behavior of the app using HTML5, CSS and JS.
So, if you are not using any of the native functionality or custom Phonegap plugins, you can just have a bare minimum package structure of native apps for each of the platforms and then simply move the correct files into the concerned folders (in Android it is assets folder) of those package structures using copy task of ant. Thereafter, you can use command line compile and build tools specific to each platform to build and package the app.
Hope this helps.
EDIT: Added more details about other platforms
Basically, all SDKs contains command line tools. In fact I used to compile and build from command line, to automate the process, even for standard Windows apps (Console, Web Apps etc) which are usually performed via Visual Studio's easy to use environment. You can see this for extended tools over standard SDK for Windows phone development.
Similarly iOS is based on UNIX so there we get the power of majority of command line tools for compile, build and automation and XCode provides command line tools for building.
Further for Android, you may find this helpful.
You should really be using Cordova, the renamed version of PG that is an Apache project now. Command line tools were recently released for Cordova. I have not used them so I am not sure if they will help you with building or not. Typically the way you woul create the binary for the device, say an IPA file for iOS would be to actually use Xcode and the native SDK to compile and package your app. This means you need all of the native tools and SDK for each platform. There is also a hosted service from Adobe that will build the native bits for you for a fee. It used to be called phone gap build, not sure if that is still the name. You might want to look at IBM Worklight, as it does many if the things you asked about. The developer edition is free an Eclipse based for the IDE.