Java Compiler multi-platform - jar

How could I compile a Main.Java program to something that I could run with OpenJDK Java 6 or 7 . The program doesn't contain anything besides displaying the message "Hello World"
I would like to compiler to .JAR
Also if I compile the program will it run in Windows or do I got to cross compile like C++ if I'm using Linux as the native developer.
I'm using the Linux Ubuntu OpenJDK Development Kit (JDK)
This is how you compile.
cristian#ubuntu:~/Java$ javac Main.java
but how would you compile to a .JAR file so I can run it in my Windows.
Any guides to learning Java are welcome and thanks for the help.
I'm using Linux Ubuntu.

You must specify your main class in the JARs manifest in order for it to be runnable. You can then invoke your application from it's jar as follows
java -jar application.jar
Current versions of the JDK for Windows will create a file association for .jar files so if you click on them they will execute.
For further details, take a look at Oracle's Jar Tutorial, specifically the section on Setting an Application's Entry Point
Edit
Regarding the need for cross compilation... Since Java compiler targets a virtual machine, you do not need to cross compile for different operating systems. (One of the early taglines for Java was "Write Once Run Anywhere".)
Here is a decent article on the basics of how the JVM does its magic: What Is The Java Virtual Machine & How Does It Work?
The Oracle Java Tutorials are an solid starting point for many things java related and I recommend reading through them if you are new to Java.

Java's JAR files are platform independent and only require an installed JRE/JDK.
OpenJDK does almost the same thing as Oracle JDK however you can also get the Oracle JDK on Linux Ubuntu by using third-party repositories such as ppa:webupd8team/java(details on how to use the repository are provided on the webupd8 website) i found i needed to switch to oracle java for performance issues.
Most common IDE's for java provide support for compiling and packaging to JAR/Runnable JAR.
A popular java IDE is Eclipse(http://eclipse.org) other popular IDE's include NetBeans and JetBrains IntelliJ IDEA.
Most programmers use IDE's for ease of use and other functionality such as IntelliSense(Autocomplete), error checking, Syntax highlighting and debugging.
A good guide to learning java is http://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28. Other guides such as java game development can also be found on Thenewboston's channel or thenewboston website.

Related

how to setup the kaa platform develop environment?

We download the Kaa platform source code from git.
We can build it successfully under linux OS.
And we also try to import it by Eclipse.
But, it will show a lot of error after import Kaa project into Eclipse.
Does the develop environment need under linux and need to use other develop tool??
Have anyone can share the guide instruction to help setup the Kaa platform develop environment??
Thank you!!
We try to use IntelliJ IDEA (community version) to import all source from git.
And then, use the "Generates Sources and Updates Folders" function of Maven to generate some source that it need.
After generating the source that lack before and the project can be built successfully.
Finally, we use the package command to generate the rpm and deb file.
Above all operation is on Linux OS.
The Eclipse should also support above operation, but it should be more setting need to set. And it seems more convenient by IntelliJ IDEA.

QT Creator, compiling and deploying a c or c++ to a remote device (BeagleBone or R pi)

I'm trying since days to write and develop programs on my host pc (Ubuntu 64bit) using qt-creator for my beaglebone and raspberry pi devices.
I looked for 'qt-creator cross compile beagle, raspberry etc...' and it leads me to hundred of links and tutorial on how to compile qt-creator for my target plattform. But seriously, that not my idea. All what I want is to simply use my pc for developing my programs and lately deploy them to the remote device.
So first of all a noob question: Is something wrong with my idea? Should I really compile the source of qt for beaglebone or raspberry on my pc for writing programs which lately should be run on that devices????
I will not compile qt-creator again for another plattform, so I don't know how to find the right way. A lot of informations on internet are misleading.
So after many hours spend look for the right information I come up with the following procedure:
first I installed a arm-gnu toolchain on my 64bit Ubuntu.
sudo apt-get install build-essential libc6-armhf-cross libc6-dev-armhf-cross binutils-arm-linux-gnueabihf linux-libc-dev-armhf-cross libstdc++6-armhf-cross gcc-4.8-arm-linux-gnueabihf g++-4.8-arm-linux-gnueabihf
then I installed qt-creator from the repository on my Ubuntu:
sudo apt-get install qtcreator
I tried to configure to use qt for compiling my projects using the toolchain for arm (see following pictures)
and here:
but it seems that qt-creator doesn't recognize the new kit when I start a new project:
Now: I m really confused, I could think that the problem is related to qt, but I m not sure, whether the way of thinking, that I can compile on ubuntu 64bit and then run my application on the remote device is right or not.
For this reason it would be nice if you can answer the question above.
UPDATE: What happen if I add a QT-Version in my Kit???
It happens that the gnueabi compiler conflicts with that options and the following problem arises:
I would like to say again that I don't need to use qt-library or something like that on my remote device. I need just to use the qt-IDE as IDE for my projects (mainly c or c++ plain projects)
You need a complete toolchain
A toolchain is just a name for a group of things:
Compiler for the target platform (or cross compiler in your case)
Sysroot: An image of the filesystem in the target platform
A cross compiling qmake
QtCreator and the kit
You are lacking a cross compiling qmake. Please see my answer at this other post.
Furthermore, you need a toolchain for the Pi, and another toolchain for the Beagle.
It looks like before the update in the question, you didn't even have a valid kit, so there was nothing the IDE could do. You need to create a kit, and set Qt Version to None - because whatever Qt version you have installed is not for the ARM target. So, as long as it'll be none, it should work then, assuming that you have installed a full ARM toolchain for the target, including the Linux-specific bits - since you're not building a bare-bones application, but an application that will run on Linux.
When creating a new project, make sure to select Non-Qt Project, either C or C++, and choose the CMake build system (not qmake or qbs).
To test this out, start with creating a kit for your host platform, without selecting a Qt version (set it to None), and make sure you can create a simple C project and build it (choose proper compilers etc). Once you have done that, you should have an idea how to proceed with building for your ARM Linux targets. It really shouldn't be problematic at all (it all "just works" in my experience), so you probably didn't install something major (related to the target toolchain, nothing to do with Qt nor Qt Creator).
In Derek Molloy's tutorial for the Beaglebone on this subject, he mentions at around minute 18 that installing QT directly through the command sudo apt-get install qtcreator, won't install all the features of the QT app.
Try downloading QT directly from Qt site.

Packaging a qt application compiled with shared libraries

I downloaded the qt embedded demo source code recently on my linux machine. Following are the outcomes during running of the program
I compiled it statically on my x86 machine and run the application on x86 machine it runs fine. But when i took the statically compiled binary file to other machine with Atom platform It run with some missing widgets. I found that the plugins cant be ported with static compilation. Can anybody tell me is it true? If no can anybody tell me the steps for it?
I compiled it dynamically with shared libraries. Then got an executalbe on linux. I did "ldd MyAppName". It show me the shared library files it is using. But I dont know how to package these. Can anybody tell me the steps to package it?
I checked in the article on deploying qt applications on X11-linux platforms. But its not complete. Can anybody give me the detailed steps?
Any help will be appreciated......
you either have a distro, that does'nt support atom, or libraries, that are not compiled with support for it. either way - something somewhere on your system (or your qt) is not compiled for atom
The problem is that you are compiling your app, and its libraries (static or dynamic) work for x86, not for Atom. Perhaps you are able to create some sort of fat binary (lipo?) so that pieces of your app will function on x86 and Atom, but bits using the x86-only libraries will not function on Atom. (Right? That's a concise definition of your problem?)
If you have the source code for the libraries that don't run on Atom, and they're important to you, you should consider porting the code to Atom. If it's open-source code, you can contribute to the project. While you didn't give many details, my (very generic) approach to this would be to get the code on an Atom machine, write a very short test application for the library, and work out the issues.
Re #2: There's little difference between compiling an app and linking to shared libraries or dynamic libraries. On your x86 machine, if you have this code (these "plugins") compiled as dynamic libraries, it's pretty much the same as statically linking those binaries into the app. These libraries will work on x86, whether they're dynamically or statically linked.
I'm not sure if that helps very much -- if you're getting binary Qt plugins as static or dynamic libraries without source, you're out of luck. Submit a bug report. If you have source code, you can do a lot more.
I just dynamically compiled my application and ported to atom platform. I found the dependencies and ported them also and set the environment variable LD_LIBRARY_PATH on target machine to my ported shared libraries and It worked. Thanks everybody for your suggestions

How can I convert a JAR file to an EXE file?

I want to created a JAR file and I want to run it on a client machine.So, I have a couple of questions:
How can I convert the JAR file to an EXE file?
How can I encrypt the JAR file's contents? The jar file could be extracted with WinRAR and the classes could be decompiled with any Java decompiler.
How can I create an installer? My clients doesn't have any JVM and I don't want to ship JDK or JRE along, because they have big size.
See this link: Java to Exe. It also explains what valid reasons are to do this, and when you should not.
You can't really encrypt binaries as the machine has to understand them. That said, an optimized executable is very difficult to decompile, while plain class files are ease.
If you have an exe there are installers enough.
JSmooth is a application which will wrap your Jar in an exe
it also allows you to check if the correct version of JRE is available on the system you're deploying to
http://jsmooth.sourceforge.net/
As for 1): I guess you can not. There may be tools out there, but you cannot do that with standard tools shipped with JDK, as it would destroy platform independance. (See other answers providing links to such 3rd party tools)
As for 3): Use InnoSetup to create the installer. Include JRE within setup and let InnoSetup install it on the fly.
You can't prevent decompilation. The best you can do is make it harder or more time-consuming to do so. As an answer to your question though, I believe you can use gcj to compile Java into EXEs.
May be Excelsior JET will satisfy your needs.) IMHO very mature product.
1) I have recently tried the program jarToExe and like it.
Some features are:
free basic version or very cheap ($30) for 'enterprise'
ability to have windows task manager list your app's name instead of the default java.exe
extra obfuscation
runtime check that java is installed
2) You can make it harder to reverse engineer using proguard or other obfuscator
3) nsis is a very powerful, free scripting language to create windows installers. Good documentation on the site wiki and support on stack overflow as well.
Launch4j worked for me while some tools hadn't been working. It also have a good guide here.
Hope this help!
We use a 7zip SFX install launcher. This is an open source simple tool. It will package your jar, a version of jre so it's not mandatory for the installing systems to have jre installed and a self extracting version of 7zip. Here is a tutorial which explains how to bundle and GitHub link
The project is not maintained but works perfectly(tested until Java 1.8)
1) To create the exe, you can use Launch4j
2) As I have seen, you cannot encrypt the jar contents. I'm not sure though.
3) To create the installer you can use the exe you just created and use InnoSetup to create the files. You have to embed the jre inside the installer and also any other libraries and extra files that may need in the runtime. When embedding the jre, the setup gets large and if you want to avoid that, you can ask the clients to install java in the machines. That way, you wont need to ship with the jre.

How to build QTcore4.dll without dependency to MSVCx80.dll?

I have a windows screensaver that I want to recompile using the QT libraries, so that I can make available for more platforms.
I am facing problems with the deployment on Vista and XP.
I compile my screensaver statically with MT, and run the dependency checker.
The results are:
MyScreensaver.SCR needs several DLLS, QTCORE4.DLL but no MSVCx80.DLLs.
So far this is fine.
My problem is that QTCORE4.DLL in its turn, does need MSVCP80.DLL and MSVCR80.DLL
As a result my application does not run on Vista systems.
Can I build QTCORE4.DLL to be statically linked the the microsoft libraries (maybe Libcmt.lib ?) so that I do not have any dependencies in the MS CRT DLLs?
Limitations:
I do not want to have the users install the MS VC redistributables. The screensaver is only 1 MB, and it is ridiculus to ask the user to do so many changes in his computer just for a screensaver.
I do not want to use the trick to put the MS CRT dlls in the same application path with the screensaver because screensavers are installed in system32, and I want to install the minimum possible files there.
Finally, I do prefer to produce a monolithic program, rather that a bunch of DLLs
I tried a full static compilation and link of QT, but this is not allowed (if I understood correctly, by the LGPL) and also it is not recommended according to this: http://www.qtsoftware.com/developer/faqs/why-does-a-statically-built-qt-use-the-dynamic-visual-studio-runtime-libraries-do-i-need-to-deploy-those-with-my-application
After trying for solutions in various directions, it seems the most feasible one is to use the QTCore4.dll and QTGui4.dll, but having them linked statically to MSVCRT. In this way, neither my program, nor the QT DLLs will have dependencies on MSVCRT dlls.
Is there a solution to this?
( I am new to QT programming )
Thank you,
Michael
I think they are concerted that parts of your application will be compiled with /MD(d) and parts with /MT(d), but if you control everything (including 3rd party libraries) then its pretty safe to use /MT(d).
You have two options:
Those dependencies are part of Microsoft Visual C++ Runtime Library, you can deploy that library in your installshield and user silently installs it, MSVCRT library not included in Windows by default, you must deploy runtime library in your installshield and copy Qt*.dll DLLs in your application directory.
Use Static Linking of Runtime and Qt main dependencies, with this option you have one executable file, but to static compile of Qt you must have Qt commercial License for commercial use.

Resources