Posts mit dem Label Java werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Java werden angezeigt. Alle Posts anzeigen

Mittwoch, 24. August 2022

Getting the google-java-format plugin to run in Eclipse with JDK >= 16

The google-java-style plugin can be found here. You can download the newest version in their release folder. Installation is pretty straight forward - just copy it into the dropins folder of your Eclipse installation folder.

but if you are running on a JDK with a version >= 16 it simply will not work. Going through the release history of the plugin you'll find a comment for version 1.10.0. If you are running the Java formatter, you'll hhave to add some VM args, when you start your Java application.

In order to get this working with your whole Eclipse IDE you'll have to edit the eclipse.ini in the following way. Took me a little bit, because I forgot the equals after the add-exports:

-vmargs

-Dosgi.requiredJavaVersion=11
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-Dsun.java.command=Eclipse
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=11
-Dosgi.dataAreaRequiresExplicitInit=true
-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true
-Xms256m
-Xmx2048m
--add-modules=ALL-SYSTEM
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

The first part might differ. The important lines are the --add-exports.

Dienstag, 28. August 2018

Decompiling an Android APK file

I recently needed to look into another Android app to see how they implemented some strange UI behaviour. There are a few steps neccessary to get the source code of an app.


  1. Download the APK from the device.
  2. Convert the APK file to a JAR
  3. Decompile the JAR

Download the APK from the device


This can be done using the Android SDK platform tools. Go to your SDK directory and find platform-tools/adb.

If you don't know where your application is installed on your device follow these instructions:

Type 

adb shell

This gives you a Linux shell on your device. Now type:

pm list packages -f

This will give you a list of all your installed applications and the paths where they are located in the filesystem.

Exit the shell and download the APK via:

adb pull <Path to the APK file on the device>

Now you can find the APK file in your current directory.

Convert the APK file to a JAR


Now we use the dex2jar tool to convert the Dalvik executable files into class files inside a JAR. Download the tool from the github repository and run

sh d2j-dex2jar.sh -f ~/path/to/apk_to_decompile.apk

This creates the JAR archive in the current directory.

Decompile the JAR


Now we can use the Java Decompiler to view the contents of the JAR archive. Just open the JAR archive in the Decompiler and browse the classes.


Freitag, 2. März 2012

Java: Creating an undecorated window with LWJGL

This system property removes the window decorations (title bar, icons, border) from LWJGL applications in window mode.

org.lwjgl.opengl.Window.undecorated=<true|false>

You can specify the property on the command line, when you start the application

java -Dorg.lwjgl.opengl.Window.undecorated=true -jar application.jar

or in your code by setting it manually.

System.setProperty(" org.lwjgl.opengl.Window.undecorated", "true");

See the LWJGL wiki for more hidden property switches.

Sonntag, 12. Februar 2012

Java Slick game development - 64 bit problems

When setting up my project and writing the simple basic application Slick crashed on me with an error:

java.lang.UnsatisfiedLinkError: Drones\lib\lwjgl.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform

I'm running Windows 7 on a 64 bit system and I have the 64 bit Java VM installed. You will not see this error if you are running the 32 bit version of Java on your 64 bit system.

To solve this problem I had to download the current version of LWJGL from their site and copy the windows DLLs and the lwjgl.jar that is included in the download into my project lib directory. This will replace the lwjgl.jar that came with the Slick distribution.

So now my project looks like this in the project explorer:

Samstag, 11. Februar 2012

Java: Slick game development - Part #2 The first program

After setting up the project in my last post, we now create a very simple sample application that we will extent in the future.

The following code creates a new Slick game. It is not much yet - just a black window. But this window is already an OpenGL frame.

package codebrocken.drones;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

public class Drones extends BasicGame {

 public Drones(String title) {
  super(title);
 }

 @Override
 public void render(GameContainer arg0, Graphics arg1) throws SlickException {
  // TODO Auto-generated method stub

 }

 @Override
 public void init(GameContainer arg0) throws SlickException {
  // TODO Auto-generated method stub

 }

 @Override
 public void update(GameContainer arg0, int arg1) throws SlickException {
  // TODO Auto-generated method stub

 }

 public static void main(String[] args) {
  try {
   AppGameContainer appContainer = new AppGameContainer(new Drones("Drones"));
   appContainer.start();
  } catch (SlickException e) {
   e.printStackTrace();
  }
 }
}

The class itself is derived from BasicGame, which does a lot of work for us. We just have to implement a few methods that will do our actual work later. The main method creates a new AppGameContainer and initializes it with our game.

Freitag, 10. Februar 2012

Java: Slick game development - Part #1 Setting up Eclipse

Slick is a 2D game library for Java. It uses OpenGL for rendering. It also contains a lot of utility functions. I want to do a little bit of game programming so instead of writing my own engine (as I would do normally), this time I'm testing Slick.

Step #1: Download Slick libraries

You can get the Slick libraries here. Just download the complete package. It includes the LWJGL libraries that provide the OpenGL layer.

Step #2: Create a new Eclipse project

Create a new Java project in Eclipse and amed it Drones.Nothing fancy at this point.


Step #3: Import the libraries

I created a new lib folder, that will contain all my libraries. I copied the slick.jar and lwjgl.jar from the Slick archive into that folder. To add them to the build you have to open the properties of the project and select "Build Path". Then click "Add JARs..." and select the two JAR archives from the lib folder.


Step #4: Import the native libraries

The LWJGL library needs a native runtime library. On windows systems this is the lwjgl.dll you can find in the root folder of the Slick archive. I copied the DLL into the lib folder too. You can choose a "native" subfolder as you like.
You now have to open the "Referenced Libraries" branch in the package explorer and right click the lwjgl.jar to open its properties. In the properties dialog select "Native Library". Here you can select the "Location path" where Eclipse will look for native libraries, when it starts the application. Just select our lib directory here.
Under the hood this step sets the java.library.path property to point to the lib directory. This property defines where Java searches for native libraries.


Now you are done with setting up Eclipse. You should have a structure that looks something like this: