Welcome! Log In Create A New Profile

Advanced

Can Slic3r use a postprocessor written in Java? [YES - SOLVED]

Posted by RetireeJay 
Can Slic3r use a postprocessor written in Java? [YES - SOLVED]
May 27, 2015 09:43PM
The subject line says it. I'm talking about Java, not Java Script.
I do NOT have much experience with Java, so maybe it is a silly mistake I'm making. In the Eclipse IDE, I have a little program in Java (at the moment, just a hello world kind of demo) and using Eclipse, I can "Export" it to a "Jar" file. This file seems to be "runnable" in the Windows environment, but when I try to call it from Slic3r, I get a message that it can't be executed.
Does someone know what I'm doing wrong?

Edited 1 time(s). Last edit at 05/28/2015 09:21PM by RetireeJay.
Re: Can Slic3r use a postprocessor written in Java?
May 28, 2015 12:26PM
Are you trying to run it directly - by just specifying the jar file name - or are you running "java ".

I've never done this myself, but you might have better luck if you directly invoke the java interpreter since it is native executable. The jar file needs the java interpreter to run, and it's probably a windows file extension association that causes this to happen.
Re: Can Slic3r use a postprocessor written in Java?
May 28, 2015 02:37PM
Someone on another forum suggested the same thing. But it still doesn't work! Either with just plain "java - jar" preceding the patch to my Jar code, or with a full path to the Java executable, like this:
"C:\Program Files (x86)\Java\jre1.8.0_45\bin\java.exe" -jar "C:\Users\Jay\Documents\Java\HelloWorldDemo.jar"

Of course the above does work within a CMD window.

Slic3r says "The configured post-processing script is not executable: check permissions." But of course I'm using an administrator-level account, so permissions is not the issue.
Re: Can Slic3r use a postprocessor written in Java?
May 28, 2015 08:57PM
Can you run anything else that way? e.g. try this command line... CMD /C DIR

When you built your HelloWorldDemo.jar, was it built as a command line application? Or as a Java GUI application? i.e. when you run it from the command line, does it pop up a window, or does it just write to System.out (aka stdout)? I suspect that any GUI type application won't run from within Slic3r.
Re: Can Slic3r use a postprocessor written in Java?
May 28, 2015 09:21PM
Well, the answer to your question is "kinda sorta." In general, I intended to write the Java application as basically a text processor with little to no user interaction. But in order to test the simplest possible case, I wrote a little "hello world" app which pops up a GUI window. I discovered the code for this in Wikipedia. The simplest way to send a string to a GUI window is actually to use an input dialog box. So here's the entire Java program:
import javax.swing.JOptionPane;
 
public class HelloWorldDemo {
	public static void main(String[] args) {
		String MyString = args[0];
	JOptionPane.showInputDialog("Hello World - Parameter is: " + MyString);
}
}

BUT - I did discover how to make Slic3r run the Java program! I wrote a little batch file called HelloWorld.bat, which encapsulates the Java command line. And it works. Slic3r passes the path and filename of the G-code file as a parameter to the batch file, and the batch file in turn sends it on to the Java program (via the %1).
java -jar "C:\Users\Jay\Documents\Java\HelloWorldDemo.jar" %1

Of course, this is a Windows solution. Probably there are similar techniques that could be used on Mac and Unix-family platforms.
Re: Can Slic3r use a postprocessor written in Java? [YES - SOLVED]
May 29, 2015 07:39AM
I think that the issue is that a ".jar" file is not an executable file, so cannot be opened or run directly from another application (unless that application has specific handlers for java files). When you double-click on a .jar file directly, the OS looks up the .jar extension in its list of file associations, which tells it to execute the Java application elsewhere on your PC and pass the .jar file you clicked on as a parameter. The PC I am using now does not have Java installed, so if I were to copy your JAR file to my PC and double-click on it, it would not work - because my OS would be just as mystified about what it is supposed to do with such a file as Slic3r is. Slic3r does however know about the common types of executable & batch files (.exe, .cmd, .bat). So you either have to compile your Java file into a standard EXE file, or do as you have done and call it from a BAT file so that the OS gets involved. Compiling to an EXE is the better option.

Dave
Re: Can Slic3r use a postprocessor written in Java? [YES - SOLVED]
June 02, 2016 06:06PM
hi!

Please, i need some help.... can you tell me what i have to do to execute an .exe file placed on "my documents" (its a little program developed on c++) from the post processing script?

thank you!
Re: Can Slic3r use a postprocessor written in Java? [YES - SOLVED]
June 02, 2016 06:30PM
I think if you read through the posts in this thread, and of course refer to the Slic3r manual you will find your answer.

I think the problem I was having in trying to have Slic3r execute "java -jar myprogram.jar" was that this command has (two) parameters. Slic3r wants to execute a command with NO parameters - exactly what you are asking to do. When Slic3r itself calls yourprogram.exe, it will append one parameter which is the complete path and filename of your g-code file.
Sorry, only registered users may post in this forum.

Click here to login