Making an executable jar file

Process

Right click on your Java Project and select Export.

Select Java -> Runnable JAR file -> Next.

Select the Launch Configuration and choose project file as your Main class

Select the Destination folder where you would like to save it and click Finish.

Execute

java -jar <jar-file-name>.jar

Advertisements

Why do many software engineers not like Java?

Interesting experience shared.

Answer by Costya Perepelitsa:

Let me answer by telling you about a programming test I evaluated this week. All things considered, it was solid, even succinct Java. The candidate had a ton of industry experience with Java, and it showed.
Bear in mind that none of the examples I'm about to give are what I'd call bad or dumb or unnecessarily complex; these are all, for the most part, what Java and the industry call sensible, standard practice.

Spoiled as I am with inferred typing, every time I see a line like…

HashMap
<
String
, 
Set
<
String
>> 
depMap 
= 
new 
HashMap
();

…I die a little on the inside. Because to me, that says, "depMap is a map, which is a map."
52 characters just to define a common data structure? Come on. Indentation included — and this kind of definition must be indented at least twice — this kind of crap takes up the majority of my terminal width.
Reading through basic declarations is a minor undertaking in and of itself. And when there's a block of declarations like this, my eyes glaze over and my ADD kicks in, and I suddenly and strongly want to do absolutely anything else with my time.
I would honestly rather read overly-clever and terse Perl, because I would rather put my brain to use figuring something out than push it through this kind of mind-numbing tautological filler.

And for anything even slightly more complicated, especially APIs written by card-carrying members of the Cult of Design Patterns, you see things like this:

private static final 
Logger LOGGER 
= 
LoggerFactory
.
getLogger
(
Main
.
class
);

This initializes a very basic logger from SLF4J: the Simple Logging Facade for Java.
Did you catch that word "simple"? This 73-character (69 plus the length of your class' name) monstrosity, in which the word "logger" appears no fewer than four times, is how you do simple logging in Java. It's all uphill from there.

This submission also followed the standard Java package naming convention of stress-testing my filesystem with entirely too many nested directories, most of which contained only the next nested directory:

src/main/java/com/[company]/[program]/[author]/*.java

7 directories deep, that code is. That's the number of times I had to press tab in my

cd

command just to get to the code.
And this is just for a simple one-off program; it gets all the deeper with each small step of complexity. I have seen, in my career, upwards of 20 nested directories that could not reasonably have been shortened.
With most languages, an IDE is a useful tool for managing a sufficiently complicated project; with Java, an IDE is a necessity for navigating an unavoidable labyrinth created by even the simplest of projects.

Since it used third-party libraries, as most any Java program in the industry is bound to do, my choices for compiling what was otherwise an extremely basic program were:

  • download all JARs myself and write classpaths in my compile and run commands that stretched several lines in my terminal
  • use Ant
  • use Maven

And after briefly reliving the utter insanity that come with those latter two, the first option ended up being the least painful.

The candidate was nice enough to include a

pom.xml

, so I naturally tried Maven first. Since I hadn't used it in a while, I first ran

mvn

and desperately hoped it would Do The Right Thing. But after downloading roughly half of the Internet, not to mention flooding my terminal with literally hundreds of lines describing each step it was taking, Maven informed me that I needed to specify one of its entirely too many (30, by my count) ambiguously named "goals". I spotted at least four or five that could plausibly have meant "just compile the fucking thing," but I got very sick, very quickly, of watching Maven download the same half of the Internet it had already downloaded, every single time it ran, even when it could easily have stopped early with an error message when I gave it invalid input, as I iterated through that list of possible goals. It didn't help that the output was so criminally long with each run that I lost track of where it had dumped that mega-list of goals; if my terminal continued out the top of my monitor, I'm willing to bet that list would be in outer space. I wasn't feeling like scrolling into outer space that day, and I definitely didn't feel like running

mvn

with no arguments again just to print another copy, so I looked into my other options in the vain hope that they'd be simpler.

Skimming through the Apache Ant manual revealed that I'd have to write XML to use it. I honestly believe I saved myself an aneurysm by proclaiming, "fuck that noise," and closing the browser tab.
(PROTIP: The key is hearing yourself say it out loud. Otherwise, your brain might still suspect that you're willing to try writing XML just to compile a single-file, <200 line Java program and try to end its own existence before being forced to comply.)

And thusly did I find myself Googling class names in compilation errors to find the projects that had the source to make the JARs to give the compiler to build the fucking program.
And it gave me much less of a headache than Maven did, because I at least felt like I was making progress.

This happens pretty much every time I try to do something with Java.
Writing it is a tedious, painful exercise in patience.
Reading it is a tedious, painful exercise in patience.
Compiling it is, you guessed it, a tedious and painful exercise in patience.
And even running it is somehow precisely as painful and tedious as compiling it.

Every task in Java — every task — is like filling out endless tax forms.
And I know, and you know, and Java knows, that it doesn't have to be this way, because you can some-crazy-how accomplish exactly what you can in Java using other languages that are just as portable, performant, and commonly known, but considerably less of a Byzantine clusterfuck.
And yet these problems persist.
And so I continue to keep my distance.

Why do many software engineers not like Java?

What is GitHub for a beginner and how to get started with it?

Answer by Mayuresh Waykole:

Hello,

I understand what you have been facing.
Lets start with a few basics shall we ?
Terminology :

Repository : A repository is a folder inside which you are going to store                            every piece of your code
Fork : Copying someones repository into your account is called forking.
Upstream : The guy or organisation which owns the code that you forked.
 

1. What is Git ?

Version Control System ( Keep reading and this will make sense towards the end ) .
Lets say you have a project you want to work on.
Now you have 2 primary motives.
          (a)  To write some code
          (b)  To take up the project as a team , meaning that more than  one                           people are going to be responsible for writing the code.

So suppose you write a "Hello World!" program and then your friend/other developer decides that it should say "Hello, I am awesome"
instead of the original "Hello World!".

Even for this little piece of code, you will have a copy in your PC and your friend will have one in his PC.
Lets say you change the code, now at this point your friend wouldn't know the changes you have made and vice versa.

This is where the Git magic comes. 
    1. Git lets you save your code online.
    2. Git will allow all the developers of a project to see what changes                         the  other one has made.
    3. It allows you to discuss issues in your code with other developers.
     And a lot more…

I think now you have a decent idea of what git is.

2. Getting Started

First, Signup on Github.
-> Next, Download git for you OS from this page Git – Downloads
-> Next you go and do this   Create A Repo · GitHub Help

So now you have created a repository Online, and you have installed git on your PC. Until now they are not linked to each other.

-> To do that follow the instructions under "setting up git" Set Up Git · GitHub Help

Setting Up is done !!

3. One step ahead

If you forked someones repository ( Forked , explained under terminology, scroll up ) then follow these instructions Fork A Repo · GitHub Help and then the commands below.

If you are the upstream yourself ,( ie. you are the guy who created the original repository ) then follow the instructions below

$ git clone <add the repository address here>
( Clones/copies everything from that repository to your local machine )
$ git add filename.extension
(this adds the file you want to change on the server)
$ git commit
(this commits your changes to the repository with an explanation message)
$ git push origin master
(this finally sends all your changes to the server. This is the final step of changing the code on your repository on the server)

You just started using github. Congratulations 😀

What is GitHub for a beginner and how to get started with it?

Subversion authz, passwd and svnserve.conf

I wanted to configure my subversion/svn server so that I can checkout or commit file with a specific user name and password. This type of authentication depends on three files. These are authz, passwd and svnserve.conf. Which are located in the corresponding repositories conf directory.

When we create a repository, these tree files are created automatically with default values. We have to add/edit some configurations to make work the repository properly.

svnserve.conf

I want to use a password file for authentication. So, I uncomment the following line to use the default password file.

password-db = passwd

I want  to use the default authorization file. So,

authz-db = authz

I also have to define anonymous access in my repository. I don’t want anyone to have read or write access to my repository.

anon-access=none

passwd

This password file contains the user name and password of authorized access in the repo.

So, I added my credentials.

fahmi=password

authz

This authorization file contains the

Increase MySQL max_connections for ‘too many connection error’

mysql -uroot -p

 

mysql> SHOW VARIABLES like ‘max_connections’;
+—————–+——-+
| Variable_name | Value |
+—————–+——-+
| max_connections | 100 |
+—————–+——-+
1 row in set (0.00 sec)

 

mysql> set global max_connections=500;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES like ‘max_connections’;
+—————–+——-+
| Variable_name | Value |
+—————–+——-+
| max_connections | 500 |
+—————–+——-+
1 row in set (0.00 sec)

WordPress Version Update

Get the latest WordPress zip (or tar.gz) file.
Unpack the zip file that you downloaded.
Deactivate plugins.
Delete the old wp-includes and wp-admin directories on your web host (through your FTP or shell access).
Using FTP or your shell access, upload the new wp-includes and wp-admin directories to your web host, in place of the previously deleted directories.
Upload the individual files from the new wp-content folder to your existing wp-content folder, overwriting existing files. Do NOT delete your existing wp-content folder. Do NOT delete any files or folders in your existing wp-content directory (except for the one being overwritten by new files).
Upload all new loose files from the root directory of the new version to your existing wordpress root directory.

Windows 7 Bootable USB Install

Insert Your USB flash drive.

Run cmd.exe as administrator. Read more of this post

SVN / Subversion Backup and Restore

My svn repo was at 172.17.1.62, now I want to sift it to 172.17.1.127

Previous one was hosted on Ubuntu platform, where subversion from tigris.org was installed.

The newer one is Red Hat linux and subversion is from apache.org

Both are the same source but version is different. Read more of this post

Installing PostgreSQL 9.2 contrib extension in RedHat Linux

I had a table view in PostgreSQL DB, which uses ‘crosstab‘ function.

But my PostgreSQL wouldn’t let me use it, as it requires some extensions.

Crosstab function requires ‘tablefunc‘ extension.

When I tried

CREATE EXTENSION tablefunc;

It gave me

ERROR: could not open extension control file “/usr/pgsql-9.2/share/extension/tablefunc.control”: No such file or directory

********** Error **********

ERROR: could not open extension control file “/usr/pgsql-9.2/share/extension/tablefunc.control”: No such file or directory
SQL state: 58P01

Read more of this post

Oracle JDBC Connection – Moving from Oracle Single Instance to Oracle RAC Grid

Our core oracle database has been moved to oracle single instance to Oracle RAC Grid.

I had some old Java systems, which were using JDBC connection to connect Oracle. When system moved to RAC, my systems wasn’t working. Now, I need to change my OS host file and JDBC connection string. FYI,  172.17.1.236 is my Oracle RAC’s scan ip.

For Windows,

go to C:\Windows\System32\Drivers\etc\hosts and the following entry

172.17.1.236 ORACLE-RAC

for Linux,

go to /etc/hosts and add the following entry

172.17.1.236 ORACLE-RAC

Done for OS part. Now the connection String.

Read more of this post