SPRAVA ODOSLANA
Log in

Anacode IDE

Building standalone Java applications

Leave a comment


The version 1.6 of Anacode IDE introduces the compilation of standalone Java programs. It allows users to run an Java application without the need of any installation. This is very useful, especially for those, who are just learning Java and are eager to run their first code, and don't want to go throught the hustle of learning the Android fundamentals.

So let's have a look at what it takes to run Java in Anacode and create our very first Java project. Navigate to the menu "New" and tap on the Java file type. From the submenu pick "Project":

 

 

The next step is to provide basic information in the project info dialog. Using the "Browse" button, pick a folder where you would like the project to be created. The default is your external storage path. Pick a project name and the main class package name.

 

After clicking the Ok button, the new project is created in specified folder and the class file containing the main method is opened for editting. 

 

Alright, now let's put a simple piece of code that will just output the "Hello World" string, go to the menu and hit Run to compile and execute the application.

 

Anacode will start to compile the project and if it is the first time we're running it, it will ask to provide additional execution info, which in case of Java is the arguments the program should be run with, as seen on the picture below.

 

Since in this example we simply print a string out, there is no need to put anything into the dialog and we just press Ok. 

Congrats, you just ran your first java program using Anacode IDE :). In case you have more then one file in the project, simply open any of them and hit "Run" from the menu to kick it off. The execution settings are stored once per project and can be changed anytime through the "Exec Settings" menu.

Now let's talk a bit about what's happening behind the scenes after you hit "Run" from the menu as it is useful to know if we want to use projects created by other IDE's.

The first thing Anacode does after you tap on the "Run" from the menu, is iterating through the parent directories of the currently opened file in search for the ProjectManifest.xml file. This file contains information about the class that holds the main method as well as the package it is in. Here is the content of the file for our FirstJavaProject:

 

<?xml version= "1.0" encoding= "utf-8" ?>
<manifest>
<application appname= "com.example.FirstJavaProject" > </application>
<manifest>

 

Another important thing is the folder structure of the project. Anacode expects it to be the one of Eclipe IDE, which looks as follows:

 

/ProjectRoot  
/libs - folder that contains all external JAVA libraries (*.jar)
/src - folder that contains all packages and JAVA source files
/ProjectManifest.xml - the project manifest file

 

If the ProjectManifest.xml is missing or the folder structure isn't right, the project execution will fail. That means that for any third party project we have to create the manifest file and the folder structure manualy. This can be easily acheived by creating a new empty Java project, the same way as discussed above, and setting the project name to be the name of the java file holding the main method and providing the name of the package the main class is in. After this step, all that needs to be done is to copy all the source code files (along with the subdirectories) into the /src folder of the new project and all the external libraries (.jar) into the /lib folder.

And that's it, now just open any source code file from the project and hit Run!

Enjoy :)