How to create a modularized ear project in maven

This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api).

How it looks like (assuming our top project is named ipiel):
+ipiel
 +ipiel-ear
 +ipiel-web
 +ipiel-api
 +ipiel-ejb

*Note that ipiel, can also be a child of a another project, which could be a main project where ipiel is just a component.

How to create the 5 listed maven projects above (I'm assuming you have eclipse with maven plugin installed):
1.) ipiel (the main pom project)
  a.) In eclipse create a new maven project, skip archetype selection so it will only create a maven project that has a src folder no main/test.
  b.) groupId=com.ipiel
       artifactId=ipiel
       packaging=pom
       version=leave the default

2.) ipiel-api (where interface is declared that is shared between ejb and web)
  a.) Right click the ipiel project and select new->maven module
  b.) Since this will contain java files, select maven-archetype-quickstart, you can filter "quickstart"
  c.) groupId=com.ipiel
       artifactId=ipiel-api
       packaging=jar
       version=leave the default
  d.) Create a class Bird and add a method fly.

3.) ipiel-ejb (the backing/manage bean)
  a.) Right click the ipiel project and select new->maven module
  b.) Since this will contain java files, select maven-archetype-quickstart, you can filter "quickstart"

  c.) groupId=com.ipiel
       artifactId=ipiel-ejb
       packaging=ejb
       version=leave the default
  d.) Add dependency to ipiel-api, and implement the Bird interface, in a class let's say Eagle.
<dependency>
<groupId>com.ipiel</groupId>
<artifactId>ipiel-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

4.) ipiel-web (the ui project, where you define your xhtml files)
  a.) Right click the ipiel project and select new->maven module
  b.) In the maven filter enter "web" and select org.codehaus.mojo.archetypes webapp-javaee6.
       It's a simple web archetype and we need to add some files to it.
    1.) Add a new source folder /src/main/resources.
    2.) Inside /src/main/resources create 2 folders /META-INF and /WEB-INF
    3.) Normally we have beans.xml and web.xml inside /WEB-INF folder and /META-INF contains MANIFEST.MF
  c.) groupId=com.ipiel
       artifactId=ipiel-web
       packaging=war
       version=leave the default
  d.) Make sure that you add maven-war-plugin in pom.xml.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- In version 2.1-alpha-1, this was incorrectly named warSourceExcludes -->
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
  e.) The web project is also dependent on ipiel-api, since it needs to call it's backing bean from the ipiel-ejb project.

5.) ipiel-config (where I normally place persistence and resource files)
  a.) groupId=com.ipiel
       artifactId=ipiel-config
       packaging=pom
       version=leave the default
  b.) Create a new maven module, and select maven-archetype-quickstart, you can filter "quickstart"
I defined where my resources are in this project:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

6.) ipiel-ear (the output project)
  a.) Create a new maven module project, skip archetype selection, so we have a basic maven project
  b.) groupId=com.ipiel
       artifactId=ipiel-ear
       packaging=ear
       version=leave the default
  c.) 

Moralsk feilspor om Hellas

Kalle Moene mener i sin kronikk lørdagens DN at Tyskland og EU er ansvarlig for gresk gjeldsoppbygging og korrupsjon. Dersom Moenes hypotese er sann, hvordan forklarer vi at ingen andre europeiske land er i samme situasjon som Hellas?

Uansett om Tyskland og EU skulle ha et moralsk ansvar, så er det et feilspor. Den greske tragedien løses ikke ved å vifte med pekefingeren, uansett hvem vi peker mot. Poenget som jeg ikke tror det er uenighet om, er at Hellas trenger reformer og erfaringen viser at landet ikke er i stand til å gjennomføre disse selv. Det er sannsynligvis heller ikke særlig kontroversielt å hevde at gjelden som grekerne er i stand til å betjene uten slike reformer er nær null. Det er også et faktum at det per i dag ikke finnes vilje til å låne Hellas mer penger.

DN har skrevet om studien til Carmen og Trebesch (CT) som viser at gjeldsnedskriving gir best effekt på BNP, men vi må huske på at gjelden allerede er nedskrevet. Hellas tilhører nå det lille mindretallet i CT’s utvalg der sanering ikke hadde positiv effekt. CT’s resultater er dermed ikke lenger relevante for Hellas.

Krisen skyldes at hellas ikke har klart seg etter en betydelig nedskriving og restrukturering av gjeld. Å slette gjeld nå, uten å få noe igjen i form av reformer, vil være uansvarlig. Det viktigste for Hellas nå er en overkommelig gjeldsbetaling. Den nominelle gjelden er av liten betydning. Det er kontantstrømmen som teller.

Is Germany's Trade Surplus a Problem?

Ben Bernanke's recent post "Germany's Trade Surplus is a Problem" got me thinking about "global imbalances" again. I'm still not sure what to make of the issue. May as well think out loud.

The word "global imbalance" sounds ominous. What does it refer to? Let's start by thinking "locally," as in an economy consisting of you and me. Suppose we both work producing a good that each of us desire. From my perspective, any goods you ship to me are "imports." From your perspective, the goods shipped to me constitute "exports." If you export more than you import--so that your net exports are positive--you are running a trade surplus and I am running a corresponding trade deficit. This is the definition of "imbalanced" trade.

There is the question of how goods are paid for and how any imbalance is financed. Suppose we live in a common currency area. One possibility is that is that we pay for our shipments fully with money. At the end of the day, your trade surplus implies that you acquired more money from me than I acquired from you. Putting things this way leads us to question the notion of "imbalanced" trade. Sure, I acquired more goods from you--but you acquired more money from me in exchange. It all balances out, doesn't it?

Yes, it does. But it's still true that you exported more goods than you imported. And that extra money you acquired...what do you plan to do with it? Sit on it forever? (Actually, I explore this possibility here.) More likely than not, you are planning to spend it one day. When that day comes, I will be induced to sell you more goods than I buy from you. It will then be my turn to run a trade surplus--an act that renders trade "balanced" in the long-run.

Nothing fundamental changes in the story above if my trade deficit is instead financed by me paying you with a private or government debt instrument, or by me issuing you a personal IOU.

But what if the pattern of trade just described persists? What if you just keep sending me more goods than I send you? Then you are running a persistent trade surplus and I am running a persistent trade deficit. You are acquiring more money and securities, while I am depleting my money and possibly issuing debt.

Well, that's right...but so what? Maybe I am young and you are middle-aged: my growth prospects look great and yours appear diminished. I am a vibrant emerging economy and you are an advanced mature economy. Maybe it makes sense for the mature slow-growing economy to lend goods (especially capital goods) to the fast-growing economy. Indeed, Kollman et. al. (2015, pg. 53) estimate that strong growth from emerging economies contributed significantly to the German trade surplus, especially in the 2001-08 period. (Labor market reforms and an increased private saving rate are estimated to have had a larger impact since 2008.)


If we abstract from credit risk--the possibility that I or some other emerging economy may falter in some manner and fail to repay, then a persistent trade imbalance looks like an all-around good thing--something to be welcomed, not discouraged. And even if debtors do fail to repay, so what? Creditors presumably enter into lending arrangements knowing there is a risk of default. (Things become more complicated when we add elements like governments prone to bail out creditors, and creditors that become overzealous in their desire to make collections. But I'll leave this story for another day.)

So what is the problem with Germany's trade surplus? Let's say you're Germany and I'm a country in the periphery--e.g., one of the so-called PIGS. Both you and I are wobbled by the 2008 financial crisis, but me (a debtor) relatively more so than you (a creditor). Suppose, for example, my growth prospects are suddenly diminished--I'm looking more like the mature slower-growth you lately.

Since our growth prospects are now more aligned, there's not much of a rationale for you to run trade surpluses and for me to run trade deficits--at least, not with each other. What this means is that you should no longer work so hard to make goods for my market. And because I now borrow fewer goods from you, I'll have to work a little harder myself to make up the difference. Except that you go and spoil everything by wanting to remain super busy. So you continue to work hard to export goods to me. And because my market is flooded with your goods, there is no real opportunity (or maybe even desire) for me to work harder--it's tough to compete with you. Your trade surplus translates into a lack of demand in the periphery. Why don't you use your surplus to build yourself a bridge, or something? That'll be good for you and it'll be good for me.

That's the Bernanke point of view in a nutshell. I don't think it's entirely wrong, but I do have a problem with the story. Recall where I wrote "there's not much of a rationale for you to run trade surpluses and for me to run trade deficits, at least not with each other?" Well, that's pretty much what happened--with some delay and to an approximation--between  Germany and the rest of the EMU. That is, while Germany continued to run trade surpluses in the post 2008 period, these surpluses were not made at the "expense" of other EMU countries--see the following figure.


Germany's trade surplus is presently around 200B EUR. But its trade surplus with the rest of the EMU is only 30B EUR, which is only about 1% of German GDP. This is down from a peak of about 100B EUR in 2007. Here's another way of looking at it:


So given that Germany's trade surplus with the rest of the EMU is greatly diminished, maybe it's not the problem Bernanke thinks it is. (Whether the earlier surpluses are presently a problem is a different matter of course.)

I'm more inclined these days not to view trade imbalances as intrinsically desirable or undesirable in of themselves. If they are associated with a problem, I think they're more likely symptomatic than causal. To me, it makes sense that a mature economy like Germany should help finance growth in emerging economies. And should economic weakness in the periphery lead to trade becoming more balanced, this is no reason to cheer. After all, balanced trade is also an outcome associated with financial autarky.

Adopting this view does not preclude recommending some of the policies that Bernanke advocates. If the present low yields on safe assets like U.S. treasury debt and the German bund are the byproduct of malfunctioning financial markets leading to a "safe-asset shortage," then a wide class of theories suggest the potential benefits of a debt-financed expansionary fiscal policy (e.g., see here) and not necessarily because such policies stimulate "aggregate demand" (e.g., see here).

Whether additions to the public debt are used to finance public infrastructure spending, purchases of private securities, tax cuts, or something else, is something policymakers must weigh. But these decisions are likely not as important as just "getting the debt out there." The added supply is needed to prevent the seemingly insatiable private demand for the product from driving yields to zero (and lower). As the evidence suggests, in very low yield environments, excess demand for government debt is deflationary. And unexpectedly low inflation is not the tonic that economic theory prescribes for indebted countries struggling to recover from a severe recession.

***

PS. Bernanke also suggests Germany's trade surplus would have been lower if Germany had its own currency, which would presumably now be stronger than the euro against other currencies. But take a look at Switzerland, where the trade balance has grown in the face of a first stable, then strengthening, Swiss franc.


Android Studio - Displaying List View Inside AlertDialog

Android Studio - Displaying List View Inside AlertDialog


1.) Follow this code:
================
>Note: custom_dialog_layout.xml is the layout that will pop-up
>Note: row.xml is the item used for populating row
AlertDialog.Builder  builder = new AlertDialog.Builder(new ContextThemeWrapper(MainActivity.this, android.R.style.Theme_Holo));

builder.setTitle("Custom Dialog");

View customView = LayoutInflater.from(MainActivity.this).inflate(R.layout.custom_dialog_layout, null, false);

ListView listList1 = (ListView)customView.findViewById(R.id.listView1);
String[] stringArray1 = new String[] { "Bright Mode", "Normal Mode" };
ArrayAdapter adapter1 = new MyListAdapter(MainActivity.this, R.layout.row, stringArray1);
listList1.setAdapter(adapter1);

builder.setView(customView);

builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Ok

}
});

builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Cancel
}
});

builder.show();

Android Studio - Creating Material Design App Bar

Android Studio - Creating Material Design App Bar


1.) Set-up the color that we'll use for the app bar:
========================================
>Create a new xml inside values and name it color.xml
<resources>
    <color name="ColorPrimary">#FF5722</color>
    <color name="ColorPrimaryDark">#E64A19</color>
</resources>

2.) Using the previously declared color, change the style.xml to apply the colors:
=================================================================

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<!-- Customize your theme here. -->
</style>
</resources>

3.) Make a tool bar:
================
>Create a new xml layout file and name it tool_bar.xml
<span style="font-size: x-small;"><?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="4dp"

>

</android.support.v7.widget.Toolbar>

</span>

4.) Use the tool bar:
================
>Insert this code to wherever xml layout you want to display the tool bar
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>

5.) Adding additional buttons inside the app bar:
=======================================
>Go to menu_main.xml and add/paste the code below
 <item
android:id="@+id/action_user"
android:orderInCategory="300"
android:title="User"
android:icon="@drawable/ic_launcher"
app:showAsAction="ifRoom"></item>

Gresk gjeld bør ikke slettes

Det er ikke rasjonelt å slette gresk gjeld nå. Hellas må kunne vise til resultater først, slik at landet ikke forblir et evig pengesluk.

En lang rekke norske og utenlandske høyt ansett akademikere og IMF ønsker store kutt i gresk gjeld. De har selvsagt helt rett i at Hellas aldri vil bli i stand til å betjene en gjeld på 175 % av BNP. Spørsmålet er derfor når og ikke om gjeld skal slettes. Å slette gjelden nå er likevel en dårlig idé.

EU ønsker sannsynligvis ikke å kutte gjelden før de ser en bærekraftig gresk økonomi. Store gjeldskutt vil svekke kreditorenes makt. Av erfaring vil Hellas trolig bruke en slik mulighet til å hindre nødvendige strukturelle reformer.

Erfaringen viser at Hellas selv ikke er i stand til å gjennomføre reformene på eget initiativ. De må tvinges gjennom. Da er det dumt å gi fra seg det sterkeste forhandlingskortet på forhånd. Kredittselskap kutter ikke gjelden din før du har vist vilje til å endre adferd. Det kan hende EU resonerer slik overfor Hellas også.

Størrelsen på grekernes nominelle gjeld er tross alt av ganske underordnet betydning. Det avgjørende er kontantstrømmen og ikke regnskapet. Dette er noe av det første våre finansstudenter lærer.

I stedet for gjeldsslette får Hellas nå hjelp fra kreditorene i form av subsidiert rente og lang tilbakebetalingstid. Europamesteren i statsgjeld betaler derfor relativt lite til kreditorene sammenlignet med andre kriseland. Gjeldsbyrden er høyst overkommelig for grekerne.

Løsningen er derfor ikke gjeldskutt nå. Landet sliter med utstrakt korrupsjon, kameraderi, et råttent skattesystem, generøse pensjonsordninger og en ineffektiv statlig sektor. Det er liten vits i å slette gjeld uten at disse problemene er håndtert.

Som Jens Frølich Holte nevner et innsiktsfullt innlegg i mandagens DN, så har Hellas blitt satt under administrasjon før, i 1898. Det resulterte i en bemerkelsesverdig velstandsutvikling. Kjøpekraftsjustert netto nasjonalprodukt (NNP) økte med godt over fire hundre prosent de neste førti årene mens utlendinger styrte butikken. Ingen andre vestlige land var i nærheten av en slik eventyrlig vekst.

Det bør kanskje nevnes at den russiske revolusjon leverte en vekst på vanvittige to tusen prosent i samme periode. Det er likevel liten grunn til å tro at kommunisme vil gi samme resultat i Hellas i dag. Det beste for grekerne på sikt er derfor også denne gang at utlendinger tar over styringen, selv om det vil gå ut over grekernes selvfølelse.

Per i dag klarer ikke Hellas en gang å oppnå overskudd før gjeldsbetaling, selv etter ekstreme kutt i offentlig sektor. Uten strukturelle reformer må gjelden derfor sannsynligvis skrives ned til nær null for å være betjenbar.

Reformer er altså helt nødvendig og burde helst vært koblet med motkonjunkturpolitikk og ikke kutt. Kjente akademikere som Joseph Stiglitz har argumentert sterkt for dette. Stiglitz og andre ser imidlertid helt bort fra at det ikke finnes noe land i verden som vil putte mer penger i Hellas sin bunnløse kasse før reformene er på plass.

Å kutte gjelden og gi Hellas et «lykke til» vil bare medføre at de samme problemene dukker opp igjen. Det er viktigere å gjøre strukturelle endringer slik som at skatter faktisk blir innkrevd, at hull i skattesystemet tettes, at pensjonssystemet ikke er mer generøst enn kreditorenes og så videre. Dessverre er det lite sannsynlig at grekerne selv tar initiativ til å løse disse problemene.

Grekerne er ikke som gruppe late, men arbeidsbyrden er veldig ujevnt fordelt. Byråkratiet er håpløst ineffektivt og korrupsjon er utbredt. De som ikke har vernet arbeidsplass i byråkratiet må jobbe tilsvarende mer. Hellas er i dag i en tragisk situasjon, men landet har et enormt potensial som EU trolig ønsker å se før gjeld kuttes.





Poland and the United States: all that begins must end


With my previous entry, I wrapped up an impromptu series of articles that chronicled my childhood experiences in Poland and compared the culture I grew up with to the American society that I'm living in today. For the readers who want to be able to navigate the series without scrolling endlessly, I wanted to put together a quick table of contents. Here it goes.




The entry that started it all:





  • "On journeys" - a personal story recounting my travels from Poland to the US.




Oh, the places you won't go:






Poland (and Europe) vs the United States:





And now, back to the regularly scheduled programming...