Compiling and running Java, with bundled dependencies - java

Context
I need to utilize Websockets, but the ancient version of PHP we're using doesn't support them. I've decided to try a Java Websocket server. I've written a handful of Android applications in Android Studio, so I'm familiar with the basic syntax of Java, but have very little experience compiling and running java-things manually.
I'd like the server to be a single file that I can run once from the command line and forget about. To that end, I've decided to use this library which includes a Javascript chat app in the examples. I'm having trouble compiling and running the server for the example.
I'm on a Mac.
What I tried
Copy the server (src/main/example/ChatServer.java) to the directory with the rest of the dependencies (/src/main/java/org/java_websocket/).
Move into the library directory: cd ./src/main/java/org/java_websocket/
compile all library .java files and the ChatServer file into a jar: jar cfv ChatServer.jar *
Run it: java ChatServer
Receive error:
Error: Could not find or load main class ChatServer
Question
How can I compile ChatServer.java with all the dependencies into a single file that can be copied to the server and executed with a single command?

Use Maven or Gradle. Since you've done Android apps, you're probably familiar with Gradle, so I'd recommend trying that one first.

Related

Loading libraries on Raspbian

I'm running a Java application on the Raspberry Pi 3B, my OS is Raspbian.
The application (which has been written on a x64 Windows system) relies on the Dropbox Core sdk-3.0.6 to download some data from a Dropbox server. The Dropbox Core SDK needs another library called the Jackson Core 2.7.4 SDK.
I've imported both jar.files to the directory /home/lib/. I'm running the application from the following .bat file:
> java -cp /home/lib/jackson-core-2.7.4.jar;/home/lib/dropbox-core-sdk-3.0.6.jar -jar /home/ComRoll.jar
I keep on getting errors because of these libraries. Most common error is concering the jackson library: "Cannot execute binary file". Something that's maybe worth mentioning is that the error message differs depending on the order of the libraries in the .bat file. When I construct the file in the following way there are other messages:
> java -cp /home/lib/dropbox-core-sdk-3.0.6.jar;/home/lib/jackson-core-2.7.4.jar -jar /home/ComRoll.jar
I'm new to Linux-based systems and hoping I'm missing something really obvious here because I'm starting to fear that the entire Dropbox SDK wouldn't be eligible for Raspberry Pi.
The comments of mkasberg pointed me in the right direction.
I built a fat jar with the libraries I used during development on the Windows system.
Eventually there were some problems with that approach too: some of the libraries were signed. I excluded those libraries from the project and now the fat jar seems to be running smooth on the raspberry.

How to update native built JavaFX Application

I am building a JavaFX application in Intellij that will be built and distributed with an .exe installer and will be ran as an exe Application. I have been trying to find a way to allow for remote updates, but I have only found resources that update a jar file by using another jar file hosted on a website. Is there a way to allow for remote updates to a exe JavaFX application? I have though about using update4J, but sadly I have no idea how to implement it, use it, or if it will even work with exe applications. I have tried to use FXLauncher, but I am not able to use JavaFX with maven as an error occurs whenever I try adding maven framework to the project.
I am the developer of update4j.
The framework used to be complex and hard to use, but the last release (1.2.2 at time of writing) significantly simplified things leaving only one pain point, namely, generating a configuration.
So for starters, launch the framework using it's own main method:
# on classpath
$ java -jar update4j-1.2.2.jar
# on modulepath
$ java -p update4j-1.2.2.jar -m org.update4j
And read the output.
Creating the configuration is done using a builder, I'm still documenting it but the class javadoc for Configuration is quite complete.

How to compile a whole android project as JAR for using in Delphi application?

I would like to merge our Java (Android) development with the Delphi XE7 mobile (FMX) project, and seems like the best way is to have a JAR which contains a whole Java based mobile application.
Is it possible to compile Android project with it's intents and resources as JAR, and if it is - how to?
Based on this answer:
Android uses the Dalvik VM, whereas you need the Java VM to run a jar-file. So you can't run a jar-file on Android.

Java project won't compile to a JAR correctly for Android

in an app I'm working on I have an issue with a Java library which is here - https://github.com/kennydude/Boid-Twitter-API
When I run ant android which builds an Android package it builds fine and Eclipse can read the Jar fine.
But on my device it says that dalvik cannot locate any of the classes and eventually throws a ClassDef Exception.
I have used Jars before, so I'm wondering if it's my ant file that's broken
I would open your app project in eclipse (the one that depends on the Java library that is not found at run-time) and add the jar file the Java library produced to its build path. Then execute
android -s update project -p .
in the same directory as your apps' Manifest.xml file in order do generate ant build files.
After this, you should be able to build your app using ant by doing
ant debug
or
ant release
I fixed it by ensuring Ant was compiling to 1.6 of Java which is my target in Eclipse for the application.
Perhaps you're not placing your jar in the libs directory as opposed to lib directory? Here's a similar issue Java (Android) - class not found exception
First of all to build an apk with ant for Android you have to use ant debug or ant release, i don't know what ant android does and why you are using it but this command is not part of the standard approach to ant for Android, that's for sure.
Ant is just a building tools, if a developer provide a building solution in ant, does not mean that his application is for Android.
Under Android everything that is not a native library is converted in a DEX object, which is something similar to bytecode for the Dalvik, there is no jar or other container in your app.
This question may be helpful for you Adding a library/JAR to an Eclipse Android project .
There are a lot of conceptual errors in this topic, you probably want to study the Android platform before using it.

How do I use MAMP to display html/php and GWT code?

I have website files running on my local server using MAMP. The project was previously developed using gwt. I have installed gwt and ant.
Where do I put now my html/php files to be able to compile the java files and, in the same time, to display my html/php files on my local server?
Thanks!,
Mehdi
You mixed several things here, I'll try to make it simple:
GWT code is written in java, but eventually it compiles to javascript, so the actual code you deploy is javascript.
HTML/PHP/javascript/css files should be put under MAMP/htdocs
If you have the source code of the GWT application and you want to view/edit it, you can do it in a regular notepad, but i strongly recommend using an IDE (Integrated Development Editor) like Eclipse.

Categories