Executing Eclipse plugin (jdt/ast) outside eclipse IDE environment - java

Can I execute Eclipse Java development tools as a standalone process? I need to get Java program's AST structure using Eclipse JDT from another program, and to do that, I need to execute eclipse plugin as a stand-alone process behind the scene.
Is that possible? If so, how one can do that?

Eclipse/jdt and eclipse/ast is nothing more than a jar file, so one can use them to build standalone java application.
Example
I googled to find ASTExplorer as an example to make eclipse/ast plugin as a standalone java project.
The program was targeted for pretty old eclipse (3.0.2), I downloaded the 3.0.2 for Mac OS X this site - http://archive.eclipse.org/eclipse/downloads/drops/R-3.0.2-200503110845/
You need to setup ECLIPSE_HOME classpath variables in Preference -> Java -> Classpath variables
The .classpath has those classpath variables already, you can refer to this post - .classpath contents update in eclipse. As you can see it refers eclipse/jdt(art) jar files. I'm pretty sure one can change the reference to the newest version of jdt/ast without downloading the 3.0.2 version.
As I use Mac, I need to replace the swt for PC with swt for Mac. I could do that in BuildPath/Configure Build path
First remove the PC swt reference.
Then add the correct Mac swt reference.
Compile the example with the eclipse indigo/on mac
When the setup is correct, eclipse starts building the project. You can use Project -> Build Project menu. Then, you can check the application works fine in eclipse.
Generate the executable jar
Export to executable jar file.
You'll get some warnings, but you'll have a jar file.
Execute the generated jar
Just executing java -jar ast.jar doesn't work on Mac, I got a hint from this post.
Running SWT based, cross-platform jar properly on a Mac
In short, you need to run java -XstartOnFirstThread -jar ast.jar

Does it have to be Eclipses's AST? Or is any AST generation o.k.? If it doesn't have to be eclipse, I'd suggest Habelitz open source Java AST Compiler. http://www.habelitz.com/ I'm using it myself for some projects....
Well, of course you can launch eclipse just like any other process : How to create a process in Java
And then the problem becomes relaying the information back to the original process, which gets kind of messy. My suggested approach in this case would probably be to create a plugin in eclipse and have that plugin do whatever it is you think you need the AST for. You can work out messages with command line options to eclipse, or a shared file or something.

Related

Deploying a NetBeans application with JavaFX

I am attempting to build an application in NetBeans that can be deployed to and end user. I am still pretty new to deploying projects and this is by far the most complicated one I have done so please bear with me. I currently have a working application in NetBeans which utilizes JDK 15 and JavaFX 15. As long as I run things inside of NetBeans everything works as intended. I have reached a point where I want to make sure I can distribute this application outside of NetBeans. To this end I did some searching and found the following tutorial.
https://netbeans.org/kb/articles/javase-deploy.html
I was able to follow the tutorial and build the example. The build works in NetBeans, I am able to run the executable jar file in the dist folder from the command line, and I am able to run the jar file by executing it from the file explorer. Now when I attempt to do the same process with my own project I run into the following errors.
When I attempt to run the jar file in the dist folder absolutely nothing happens.
When I attempt to run the jar file from the command line using the command
java -jar "C:\Workspace\HandyAndyVersion1_2\dist\HandyAndyVersion1_2.jar"
I receive the following error,
Error: JavaFX runtime components are missing, and are required to run this application.
I am currently under the assumption that the first problem is a by product of the second. If anybody has a solution to this problem or any ideas on what I could have configured wrong please let me know and thank you all in advance.
To package a Java desktop application these days, you should be using the jpackage tool and optionally the jlink tool. These will generate a JRE image that is packaged with the application and contains the modules you need.
I suspect the issue you are running into is that the native libraries for JavaFX are not present. Most distributions of JDK 15 do not contain the JavaFX modules, though some do. (See the Full and FX bundles of the JDK from Azul and Bellsoft). I find it is easier to use a JDK with JavaFX bundled rather than have to manage a separate module path during development for the jmod files of JavaFX, but that is another option. Either method can be used with jlink to create a suitable JRE for your application that includes the JavaFX modules.

Running JavaFX Application on another machine

I'm trying to distribute a JavaFX application.
As an example project I took the JavaFX and NetBeans -> Non-modular with Maven. The code can be found here: GitHub: openjfx/samples.
On my machine this application works. But when I try to run that JAR on another machine, it says:
Error: JavaFX runtime components are missing, and are required to run this application
In the section Non-modular with Maven, that problem is being addressed. As a solution it suggests:
Properties -> Libraries -> Run -> Modulepath -> + -> Add Library and add the JavaFX12
But my project properties look different. They are missing Libraries:
Both machines run on Ubuntu and Java 11.
In my case, I work with windows systems, but I think that it's similiar on linux. the problem is that openjdk and javafx no always are available on other computers and dont are included on .jar.
When I want use my app on a other computer, I must build an installer this content:
myapp.jar
openjdk library folder
javafxsdk library folder
And on shortcut I indicate the runs commands calling all modules that I use on my app:
--module-path="../../javafx-sdk-11.0.1/lib/" --add-modules="javafx.web" --add-modules="javafx.controls" --add-modules="javafx.fxml" --add-modules="javafx.base" -jar ../../myapp.jar
In your case, maybe you only needs create a shortcut with commands and indicate correctly the routes of your .jar, openjdk and javafxsdk and, of course, download them on the computer that runs your app.

Standalone JAR packagers

I'm having some trouble getting IntelliJ to output my packaged JAR file so I can run it directly from the command line.
Are there any free stand alone packagers which I can use to manually add all my JARs and specify my main class which will properly package the JAR? I'm really only interested in a packager, not an installer with fancy windows etc.
I'm using Ubuntu and developing JavaFX applications.
I did find these and these links... I'll give Install Builder and lzPack a go and hopefully report back with a positive result.
UPDATE
Install Builder seems to require a paid license to distribute your packaged jars. Unfortunately izPack does not seem to work when I execute it from the command line using Java 9. Crashes out.
Trying Oracle's javapackager command tool next.
Looks like I need to use Ant to deploy standalone JavaFX applications.

How to use drools without eclipse JDT library

recently I am using Drools in eclipse. When I was running program, there is one exception:
org.drools.RuntimeDroolsException: Unable to load dialect 'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:310)
at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:295)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:184)
at org.drools.compiler.PackageBuilderConfiguration.(PackageBuilderConfiguration.java:162)
at org.drools.compiler.PackageBuilder.(PackageBuilder.java:277)
at org.drools.compiler.PackageBuilder.(PackageBuilder.java:205)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFactoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.adsc.cybersage.rules.DroolEngineInit.readKnowledgeBase(DroolEngineInit.java:48)
at com.adsc.cybersage.rules.DroolEngineInit.initializeDrools(DroolEngineInit.java:32)
I search online and found that this is because I didn't add eclipse JDT library org.eclipse.jdt.core.jar, then I add this jar and the program works well. But I don't want to add eclipse JDT Library because its license is strict. So is there any alternative jar which is under a not strict license I can use?
I am compiling and running Drools without org.eclipse.jdt.core.jar, calling javac and java from the command line (actually, a shell script).
PROTOBUF=protobuf-java-2.4.1.jar
root=/extra/drools-distribution-5.5.0.Final/binaries
tag=5.5.0.Final
export CLASSPATH=".:$root/drools-core-${tag}.jar:$root/knowledge-api-${tag}.jar:$root/knowledge-internal-api-${tag}.jar:$root/drools-compiler-${tag}.jar:$root/antlr-2.7.7.jar:$root/antlr-3.3.jar:$root/antlr-runtime-3.3.jar:$root/ecj-3.5.1.jar:$root/mvel2-2.1.3.Final.jar:/extra/quartz-1.8.3/quartz-1.8.3.jar:$root/drools-decisiontables-${tag}.jar:$root/drools-templates-${tag}.jar:$root/xstream-1.4.1.jar:$root/jxl-2.6.10.jar:$root/slf4j-api-1.6.4.jar:$root/$PROTOBUF"
Then javac and java are called.
Of course, when you are running within Eclipse, you may indeed need Eclipse stuff. You can develop and test under Eclipse and then compile DRL and execute your application using the aforementioned technique.

Eclipse plugin compiled in linux work on windows?

I have developed an eclipse plugin, which is compiled linux using maven Tycho plugin. But for some reason, I am not able to see the plugin in the eclipse running on windows. I am not finding anything in the log file.
As I am new to plugin development, Is there any difference does a cross platform compiled plugin would cause?
One dilemma I have in my mind is that, Does it really matter if I use windows based eclipse installation on linux, (as it is just a zip, extract it and use it) machine for compiling and building my plugin? Well, to me it appears that it does matters. I should use linux based eclipse for compiling a plugin in linux operating system.
But isn't this what is against java principle? Compile and Run anywhere?
as far as I know, if you are using UI stuff inside that plugin then you have to export it for multiple OSes ... and you need some libraries from eclipse website to export your application in linux...
If you are exporting only the plugin then you need nothing... OSGI takes care of everything
Some of the Eclipse packages are system dependent. To take one example, org.eclipse.core.resources.win32.x86 would work only on a 32 bit Windows workstation.
Check your plug-in and see if you have any of these system dependent Eclipse packages.
If you do, you have to export your plug-in with the appropriate Eclipse packages for each of the environments you want your plug-in to run.
Write once, run anywhere is a myth. Ask any Android programmer. :-)

Categories

Resources