Java beginnings using Netbeans - java

I'm just about starting to learn Java. Reading about, I installed Netbeans.
Running Apache Netbeans IDE 11.2.
The Java version is 13.0.2.
I'm promptly follow the Quickstart guide on the netbeans website.
File>>New project>> Java >> Java Application.
Errhmm, I don't have this 'Java' option. All I have is
So what's the difference between Java & Java with Maven/Cradle/Ant . At this point in time, I intend to start with basics of Java programming and then move on from there. SO which option am I meant to be starting with? If I'm missing Java, how can I add it ? Going through the installation procedures didn't give me any option to choose from.
p:s - this is all running on Mac OS Catalina

You can start with any of Java with ... option. I use Java with Ant option.
Maven, Gradle, Ant are build-tool addons i.e. they provide additional support if you intend to use any of these as your build tool.
When you choose Java with Ant option, it will let you create, compile, debug and run your Java programs without requiring anything additional. After using this option, you will get an interface as shown in the screenshot given below:

Maven, Gradle and Ant are build tool which allows you to compile, unit test, package and (if you like) even deploy your Java applications (they do support other languages btw).
I suggest you to start with one of those (Maven is very popular and probably a little bit easier than the others) instead of relying on your Java IDE specific features.
Once you master a build tool you can change IDE (IntelliJ is also a very good option ;-)) and will still work as before. You also find plenty of resources and help (like Stackoverflow) if you need hit some problems.
Best of luck!

Related

What is the default build process used by IntelliJ for Java projects?

Building Java projects straight from the IDE in IntelliJ has been nice. It's fast and it just works. I wasn't able to find any documentation on how IntelliJ does these default builds. I'm guessing it uses Ant? What I want to do is automate this fast and painless build process for anyone who downloads my project. Is that possible?
I've usually used Maven, but it's very slow and error prone. I actually wasn't even able to convert this to a Maven project, because Maven refuses to find JUnit despite setting up the dependency according to examples in the official docs. I also tried to generate Ant build files from the IDE, but those do not work out of the box and after googling a bit, seems like that is not a good approach?
IntelliJ IDEA has its own build system, called JPS. It has limited support for automatic download of dependencies and it's really hard to invoke from the command line, so it's unlikely to be the best option for everyone who downloads your project, unless you want to force them to use IntelliJ IDEA.

basic and minimal java development setup

I am using Ubuntu and I would like to know the basic tools to install so I can begin develop in java.
With 'minimal' I mean the most transparent way without fancy tools and stacks etc. Like for minimal C programming you just write code and run 'gcc file.c -o myapp'.
Thank you
Just download JDK.
Minimal tools are javac for compiling and java for executing JVM. Both are in bin directory.
You need to install JDK to start with hello world
Eclipse IDE. It's probably the most comprehensive Java IDE. I understand that isn't what you're looking for but light, simple ones like JCreator are not free to use. I don't see the sense in developing without an IDE of any kind.
Install the JDK. An IDE is a minimal requirement for development in Java. Not all developers would agree, but IMHO its the most productive way to develop in Java. I suggest IntelliJ CE which is free.

Java Build; with these requirements, what would be a good choice?

This is in regards to building a Java Project.
So I'm a bit confused on my options here.
My requirements (it's a small project):
Needs to compile Java project with specific/custom compiler arguments
Project has native libs that need to be included
need to compile javascript->java class via Rhino javascript compiler (https://developer.mozilla.org/en/Rhino/JavaScript_Compiler)
After the build I need to run another command: ProGuard (http://proguard.sourceforge.net/)
run javadocs
Package everything up in Jar (also including external data, ie, images, xml, ini, etc)
Build/create a .jnlp web start.
Available under both Win and Linux would be optimal.
this is a hobby project, so don't want to spend weeks learning/managing the build system. At most an 8-12 hour investment start to finish (otherwise it's just better to keep doing everything by hand).
btw, my IDE is Eclipse if it matters; a nice integrated plugin would be nice - but not required.
So far I think Ant and Maven are the main two build systems in use. It's very unclear to me though which one I should use or how they differ?
The other option would be 'make' under linux (or maybe cygwin). I've only used it once, but seemed pretty quick to get going/working. Is that a good option for Java or this project? Any downsides to make? Why don't more java developer's use it?
Other options?
In a nutshell: spend your 12 hours learning and using Ant.
Maven has a good feel out-of-the box, super-easy to get going and with the neat dependency management, but down the line tweaking the pom.xml (your project's maven build file) to fit your needs will require more fiddling with than if you used Ant.
To address some of your specific requirements:
you can use <compilerarg> elements with the <javac> task
for native libs you can add them with: <sysproperty> and key="java.library.path"
use Rhino with Ant (http://stackoverflow.com/questions/3526960/using-recent-rhino-in-ant-script)
there is a Proguard task for Ant (http://proguard.sourceforge.net/index.html#/manual/ant.html)
for javadoc Ant comes with the <javadoc> task out of the box
the <jar> Ant task is extremely easy to use to package everything up
there is a <jw:jnlpwar> task available from the [Ant Web Start Task project] at (http://ant-jnlp-war.sourceforge.net)
Ant is ubiquitous, it works for just about every major platform out there (Linux, Unix, Windows, MacOS)
with plenty of docs and examples available on the web, you'll pick-up Ant in no time, and those hours you'll spend learning it will probably "pay" themselves back within a couple of weeks of using it for your builds.
Eclipse integrates with Ant out of the box (http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.platform.doc.user/gettingStarted/qs-81_basics.htm)
It may not do fancy dependency management out-of-the-box like Maven (although for that you can integrate Ant with Ivy) but it certainly provides you with all the flexibility you'll ever need, and you won't find yourself "fighting" the build tool configuration file as it's fairly common with Maven.
I should probably just mention the 2 new names in Java build (and CI) tools: Hudson and Jenkins. They're fairly recent and may be interesting to look at, but I would definitely not recommend them to you and your project at this early stage.
Note: apologies for the lack of real links (only allowed 2 links atm)
Maven is the best choice here as it has integration for all of these
so go for it.
Here, quick links for you to save an extra hour to spend on learning maven ;)
Maven Compiler Options
Native Maven Plugin and Projects with JNI
Use Maven Antrun Plugin to Run rhino compile ant task
Use Proguard Maven Plugin (further details)
Maven Javadocs Plugin
Maven Assembly Plugin
Webstart Maven Plugin
Its java based so supported by most OS that support java !
It depends how quickly one can learn but AFAIK 12 hrs is sufficient to get started

How can I convert an eclipse-dependent application into an eclipse-independent application?

I developed an application in eclipse that uses many of the classes of the eclipse framework and requires eclipse to run. But now I'm being required to decouple it from eclipse and make it a standalone application. How can I do this?
You might have luck using File / Export... / Java / Runnable Jar File. This will create a standalone .jar file that should be possible to run without Eclipse. You may however need to experiment with the various settings to get it to behave exactly how you want depending on what libraries you are using.
In general however, I'd suggest using a proper build/dependency management tool such as Maven. This will take a bit of time to learn at first, but my experience is that it will make you more productive in the long run....
Start by commenting out the imports for the offending libraries. This will turn red any references to those libraries in your code. Then substitute a different library or refactor your code.
What do you mean by "decouple" it from eclipse? Do you mean you can no longer rely on any of the eclipse libraries, or that you simply don't want it running as a module in the IDE?
If it's the former, you have a lot of rewriting to do.
If it's the latter, then you'll want to basically bundle your module with an "empty" eclipse framework application. This doesn't "unbundle" eclipse, eclipse is still there, but now you don't have any of the IDE modules etc, and instead you have a stand alone ECLIPSE BASED application.
Create a standalone jar file from the Eclipse project as mentioned by Mikera, or you need to re-factor the code such that it doesn't depend on Eclipse libraries.
There is no point in creating a Java application which depends on certain IDEs or platforms. Java code should be independent (which is why it has the power to run on any platform which has JVM installed in it.
Try removing the dependency from your project to the Eclipse libraries. See if you can simulate the same thing using Standard Java libraries. If not, try to create a JAR for your project from Eclipse. If nothing works out, try looking for some 3rd party APIs.

Java packaging tools - alternatives for jsmooth, launch4j, onejar

I have used these three open source tools for packaging my java apps, but they all look like abandon-ware now. All three are very good pieces of software. What are the options now? (or is using Java for desktop app development no longer a "hot" market for app developers to build & maintain these tools?).
1) exe wrapper:
jsmooth - no new development in 2.5 years - does not support 64 bit.
launch4j - no new development in over a year, supports 64 bit, but you can't sign the exe created by launch4j, so I prefer jsmooth, but it does not support 64 bit.
2) onejar:
It works, but there has been no new development or web site update in more than 2.5 years. So, just want to switch to something that's supported / have a backup plan if it suddenly breaks with a new build of Java.
Thanks
Edgar
Launch4j has just been updated ! http://launch4j.sourceforge.net/changelog.html
Did you check IzPack? This is a great piece of software to create cross-platform installers:
IzPack is an installers generator for the Java platform. It produces lightweight installers that can be run on any operating system where a Java virtual machine is available. Depending on the operating system, it can be launched by a double-click or a simple 'java -jar installer.jar' on a shell. The most common use is to distribute applications for the Java platform, but you can also use it for other kinds of projects. The main benefit of IzPack is that it provides a clean and unique way of distributing a project to users using different operating systems.
Some really famous companies and projects use it for many years (Sun Microsystems, JBoss/RedHat, the Scala language project, some ObjectWeb/OW2 projects, XWiki and many more). If it's good for them, it should be good for you :)
Since none of the answers were approved, and JavaFX 2.2 has not been mentioned above (was not available at the time of the answers) here goes:
JavaFX 2.2 (part of Java Runtime and SDK since 7u6) allows building native exe/dmg/rpm's that tag along the full RT component as well. I believe this is a valid answer to your need, as well as an officially supported solution from Oracle.
https://blogs.oracle.com/talkingjavadeployment/entry/native_packaging_for_javafx
Have you tried IzPack (http://izpack.org/)?
You can try
http://winrun4j.sourceforge.net/
Has an exe with 64bit support and is quite easy to configure with an ini file.
As I was fed up with recent security changes in Java Webstart, I created my own tool, JNDT. It's under GPL.
It goes farther than akauppi's suggestion because it allows to create GNU Linux packages even under Mac and Windows :) I use it to create Mac bundle under GNU Linux too. For the moment, it's just a single Ant library with a few dependencies that allows to create native self-contained application bundles for GNU Linux, Mac OS X and Windows. I use it for my first person shooter and I'm very happy with it. It bundles the JRE but it can use the system JRE if you want.
P.S: JNDT is able to create a native Windows installer as an executable with NSIS even under GNU Linux.
I understand that the GPL license discourages some developers to use my tool. In this case, rather use PackR.
Maven 2 provides the ability to create a jar which contains all the dependencies as part of its assembly plugin. This combined with the jar plugin configuration of the manifest file (and specifically setting Main-class to the Class with main) is all you need to do basic packaging.
To some extent Java web start is now considered the better way to distribute Java applications and Maven 2's assembly capability combined with web start gets you everything you need without going via the exe route.
If you just want an exe (instead of a full-blown installer) you can make one with NSIS:
http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation
Yes, NSIS is an installer but you can have it just run a jar in the same directory by stripping out all of the installer stuff. Basically it works like launch4j but is a lot more configurable.
If you are using gradle, there is a plugin that uses launch4j (under the hood) and works great. It doesn't even require you to download or install launch4j, it is totally automated.
https://github.com/TheBoegl/gradle-launch4j

Categories

Resources