January 10th, 2009 — 12:07pm
These days when you find me working in Java, you’ll find me working in NetBeans. If I wanted to spend my time manually editing ant scripts, you’d probably find me working in vi instead.
I needed to add a file to META-INF in my application jar a few days ago. NetBeans provides a META-INF folder in the project window for web applications, but not for standalone java applications. There is a lot of documentation for this specific problem that will help you edit your build script to get this done but for something so basic I prefer a simpler solution.
After some experimentation I found an alternative:
- open the project window
- right-click on “Source Package”, click “New”, and choose “Folder” under the “Other” category
- name the new folder “META-INF”
- add files (.mailcap in my case) to this folder
- build as usual
- open your jar, browse to META-INF, and note that your files are now where they belong
Please note that I’m using NetBeans 6.5, and that this method could suddenly stop working in some future version of NetBeans if the build process changes dramatically.
If you have an alternative to this process that does not require build script modification, I would very much like to hear from you!
4 comments » | Java, NetBeans
January 10th, 2009 — 11:39am
- Invoking error(exception); will not log the stack trace from exception.
- Invoking error(“message”,exception); will log the stack trace.
If you’re only using error(), info(), warn(), and debug() to perform logging you’re missing out on a lot of valuable tools; take a moment to browse the Log4j API documentation for Category for details.
Here’s a simple application that illustrates this point…
package net.wakka;
import org.apache.log4j.Logger;
public class Log4jTest
{
private static Logger log
= Logger.
getLogger(Log4jTest.
class);
public static void main
(String[] args
)
{
log.
info("just a string");
log.
info(new Object() { public String toString
() {return "wakka";} });
try
{
int x
= Integer.
parseInt("yellow");
}
catch(NumberFormatException e
)
{
log.
error(e
);
log.
error("caught a number format exception",e
);
}
}
}
Console output follows…
[INFO] just a string
[INFO] wakka
[ERROR] java.lang.NumberFormatException: For input string: "yellow"
[ERROR] caught a number format exception
java.lang.NumberFormatException: For input string: "yellow"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at net.wakka.Log4jTest.main(Log4jTest.java:23)
1 comment » | Java