Java - Maven

Create a new maven project called 'javabot' with the package name 'annabel82.javabot':

mvn archetype:generate -DgroupId=annabel82.javabot -DartifactId=javabot -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Edit pom.xml file, next mvn command will get dependencies etc:

su vim pom.xml

Make a completely new /target compile – will need to run ‘mvn dependency:copy-dependencies’ afterwards to copy dependencies for runtime:

rm -rf target && mvn clean package

Compile and package:

mvn package

Copy dependencies to /target/depdencies for runtime execution:

mvn dependency:copy-dependencies

View the contents of a jar file:

jar tvf target/javabot-1.0-SNAPSHOT.jar

Run it:

java -cp "target/dependency/*:target/javabot-1.0-SNAPSHOT.jar" annabel82.javabot.JavaBot

 

To setup log4j, add libs to po.xml:

vim pom.xml
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.17</version>
<dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.6.2</version>
</dependency>

Create log4j conf:

vim src/main/resources/log4j.properties
Root logger option
log4j.rootLogger=INFO, stdout

Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L – %m%n

Update compile dependencies and then compile/package the log4j conf in to our .jar for runtime:

mvn mvn package

Then update runtime dependencies:

mvn dependency copy-dependencies