Tag Info

Hot answers tagged

21

I've implemented a java program using the JavaMail API to only fetch unread emails from a particular user (and mark it as read). This will allow you to periodically get emails from your ship traffic service. This is inspired by this blog post on Stephen Wolfram's email analytics. 1. Java code to fetch unread email from a sender Below is the java code, ...


14

To call Mathematica from Clojure, you will want to use Clojure's Java interop to access the Wolfram JLink classes to script Mathematica access. Start by launching Clojure with a classpath that includes the JLink.jar, for example with this batch file: @echo off set MATHEMATICA=C:/M/9.0 set JLINKJAR=%MATHEMATICA%/SystemFiles/Links/JLink/JLink.jar java -cp ...


14

Note that ListContourPlot3D takes the coordinates to be the position indices by default. If you want to keep the coordinates used in generating the data, then you have to include it. data = Flatten[ Table[{x, y, z, x^2 + y^2 + z^2 + RandomReal[0.1]}, {x, -2, 2, 0.2}, {y, -2, 2, 0.2}, {z, -2, 2, 0.2}], 2]; plot = ListContourPlot3D[data, Contours ...


12

Here is a more general approach. It is based on the 2D method from here. It assumes the polyhedron is not self-intersecting but imposes no requirement of convexity or even connectedness, other than that it be closed and bounded. Strictly speaking, I think this will work for an unbounded polyhedron provided it contains no vertical ray. For ease of exposition ...


11

What you did with setting the "com.wolfram.jlink.libdir" property will work. Perhaps you didn't enter the correct path, or you used the wrong JLinkNativeLibrary.dll file (meaning you used the 32-bit one from JLink/SystemFiles/Libraries/Windows, instead of the 64-bit one from JLink/SystemFiles/Libraries/Windows-x86-64, or vice-versa). But you really ...


11

I am writing this answer for a person who is familiar with Mathematica and has a good understanding of computer programming, but not so familiar with Java programming language. Using GraphStream is not so different from using any other Java library. You need to download the GraphStream core files from here and extract it. gs-core-1.1.2.jar is the only file ...


10

Preamble In fact, the relevant example can be found in the documentation, here, in the "Sample program" section. To make this useful also for folks who don't have experience with Java development in WorkBench, I will illustrate how this can be done from within Mathematica, by using the interactive Java reloader from this post. You will have to figure out ...


10

Comment I've placed a Notebook version of this post on my webspace here: http://facstaff.unca.edu/mcmcclur/polylineDecoder.zip The Notebook is actually contained in a ZIP file that also contains all the Java class files necessary to get this code to work. The Notebook sets the Java class relative to it's own directory using ...


10

We can start by creating the parts using the same code as the question: partSource = JavaNew[ "org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource", "mmagraphics.png", MakeJavaObject["abcdefg"]@toCharArray[]]; part1 = JavaNew[ "org.apache.commons.httpclient.methods.multipart.FilePart", "filename", partSource]; ...


10

Along the lines of Yamareth's answer, but probably an even better technique, is to put the following into $UserBaseDirectory/Kernel/init.m: Needs["JLink`"] SetOptions[InstallJava, JVMArguments->"-Xmx32g"] SetOptions[ReinstallJava, JVMArguments->"-Xmx32g"] ReinstallJava[] By setting the default options, you will get the desired heap size any time you ...


10

Nice answer by Mohsen, +1. I am continually impressed by the quality of the J/Link and .NET/Link expertise on this site. I have a couple remarks and then an example program. The question asked about some general tips for getting started with J/Link. This GraphStream library provides a perfect example for the typical workflow of a J/Link project. The ...


9

Here is a fast method that will "often" work. Roughly, it requires that the convex polygon have no sharp angles between faces. Preprocessing goes as follows. Create triangles from the polygons. So a 5-gon with vertices {a,b,c,d,e} would become the set of triangles {{a,b,c},{a,c,d},{a,d,e}}. For each vertex we average it's star (set of points connected by ...


9

By default the frontend will automatically launch the kernel; this is just a preference setting for the default 'Local' kernel. It's on by default since at one point or another, a user is likely going to want to start a kernel to do computations with Mathematica, and even if not, there are many services in the frontend which require the kernel (even the ...


8

As far as I know, JLink is used at least in PacletManager`, for operations like loading data on demand etc. The documentation system also uses Java. Perhaps, other uses as well. I don't think that Java is used a lot for the core language though. This code can make it a bit more quantitative: allNames = Flatten[Names[#<>"*"]&/@Contexts[]]; ...


8

Enumeration value names are accessible using LoadJavaClass to load the enum class. However, this particular case is complicated by the fact that the enum class Form is an inner member of the class Normalizer. To load it, we must reference Form by its so-called binary name: LoadJavaClass["java.text.Normalizer$Form"]; Now we can reference the enum values ...


8

There are two parts to accessing the contents of a Java Map object. The first is to traverse the iterator interface to extract the map elements. The second is to use accessor methods on those elements to extract their properties. For the purpose of discussion, let's create a map from strings to Java date objects: Needs["JLink`"] InstallJava[]; $map = ...


7

A few ideas: If it's a package that is to be used regularly, I'd put it in one of the standard locations where M searches for packages, such as e.g. $UserBaseDirectory/Applications. SetDirectory doesn't affect the search locations for packages. SetDirectory sets what's called the "working directory", while Get searches only those locations which are ...


7

I also encountered this problem. Not an authoritative answer, but here is one blind guess to what is happening. JLink has its own classloader, JLinkClassLoader.java, which calls another one, JLinkClassLoaderHelper.java. The latter is a sub-class of URLClassLoader.java. Both are used in the class JLinkSystemClassLoader.java. The second part of this story is ...


6

For your first question you can look at the customer stories in finance and analytics. You might also be interested in the recordings from the Wolfram Finance Platform virtual workshop.


6

You can use the raw integer value 16, but the correct J/Link syntax for the symbolic name is InputEvent`BUTTON1UMASK, so your code would look like this: (* Call LoadJavaClass when needing to refer to static members. *) LoadJavaClass["java.awt.event.InputEvent"]; robotclass@mousePress[InputEvent`BUTTON1UMASK]; ...


6

Bottom line is (and I've discussed this with the developer of JLink): you can NEVER make it TOTALLY impossible within the Mathematica system, because it's impossible to prevent man-in-the-middle attacks. You can enrypt/decrypt on both sides (the kernel and the JVM), but for decryption you always need to tell the other side a public or private key. You can ...


6

Massimo, I have no problem with creating/starting/running/destroying threads explicitly using JLink: Needs["JLink`"] ReinstallJava[] Do[ thread=JavaNew["java.lang.Thread"]; thread@start[]; Print@thread@getId[]; thread@sleep[10]; thread@stop[]; ,{10}] I've also shown several examples using explicit Java thread management with M code on the 2007 ...


6

One problem is that your path to javaw is wrong (you forgot the bin dir). But that quoting style is very hard to make work, and possibly flat-out wrong (I swear that example in the documentation worked about nine years ago when I wrote it, but I cannot seem to make anything like it work now; my apologies). The correct way is to invert your single and double ...


5

The question is a little broad. In my shop, we routinely use Mathematica for risk analysis and portfolio reporting, also for hypothesis testing and a variety of other front-office tasks. We have a master library of functions that we have created for these purposes over the last six years or so, and we also created the MathematicaLinkToBloomberg package that ...


5

You don't need JLink for this, because MINE program (Java version) seems to not be able to transmit the results by any data transfer protocol. Rather, you launch it from the command line, as a Java executable (jar file). It takes the name of the input data file as one of the command line parameters, and it writes its output into another file. I will ...


5

If you'll accept solutions involving other technologies, then how about using sed? On a unix system, to read in file1, delete row n and output to file2, you'd do: sed -e 'nd' file1 > file2 The quotes in 'nd' are not necessary in this case, since there is only one instruction. However, if you're doing more complicated stuff with regular expressions, you ...


5

MUnit will absolutely work for testing Mathematica code in J/Link projects. The J/Link project does indeed setup some paths and things, and you should be able to go ahead and write MUnit tests that use Mathematica code that calls Java without any trouble. When I setup your project as you stated here, and then right click on the test and either run or debug ...


5

MUnit testing is surely supported on JLink projects (I used it in JLink projects which also contained Java classes, without problems). In fact, MUnit is all about Mathematica, so you just follow the usual procedure. I actually never bothered to create configurations etc. I just took your code, created a J/Link project, and run the unit test file as Run As ...


5

I did not try it yet, but Clojuratica may be what you need. The project seems to no longer be maintained though (although I may be wrong). No idea how much of a problem this is, given changes in the Clojure since the time Clojuratica was released. Of course, Seth's talk was also great and is a great resource as well, as Joel mentioned.



Only top voted, non community-wiki answers of a minimum length are eligible