javac classpath multiple jars

Tengo esto en mi directorio:

 CividasSara.jar
 Main.java
 cividas.jar
 cividasnotifications.jar
 ontimizeEN.jar
 ontimizeWeb.jar
 salida.out
 util-java.jar
 workflowEN.jara

Quiero compilar Main.java (crear Main.class):

WINDOWS
javac -cp "cividas.jar;cividasnotifications.java;CividasSara.jar;ontimizeEN.jar;ontimizeWeb.jar;util-java.jar;workflowEN.jar;." Main.java
LINUX
javac -cp "cividas.jar:cividasnotifications.java:CividasSara.jar:ontimizeEN.jar:ontimizeWeb.jar:util-java.jar:workflowEN.jar:." Main.java

Con lo que ya se ha generado el compilado:

 CividasSara.jar
 Main.class
 Main.java
 cividas.jar
 cividasnotifications.jar
 ontimizeEN.jar
 ontimizeWeb.jar
 salida.out
 util-java.jar
 workflowEN.jara

Ahora quiero ejecutarlo:

WINDOWS
java -cp "cividas.jar;cividasnotifications.java;CividasSara.jar;ontimizeEN.jar;ontimizeWeb.jar;util-java.jar;workflowEN.jar;." Main
LINUX
java -cp "cividas.jar:cividasnotifications.java:CividasSara.jar:ontimizeEN.jar:ontimizeWeb.jar:util-java.jar:workflowEN.jar:." Main

ANEXO I

Ejecucion de una clase, pasando un parametro como argumento. Mantenemos las librerias en el classpath.

$ java -cp "cividas.jar:cividasnotifications.java:CividasSara.jar:ontimizeEN.jar:ontimizeWeb.jar:util-java.jar:workflowEN.jar:." es.tecnocom.tsafirma.AFirmaImpl Factura-e_2013092520130925.xml

ANEXO II

El Anexo I en un script bash.

#!/bin/bash

java -cp "bduac.jar:cividas.jar:cividasnotifications.jar:CividasSara.jar:commons-beanutils.jar:commons-collections.jar:commons-digester.jar:commons-fileupload.jar:commons-io.jar:commons-lang.jar:commons-logging.jar:jboss-el-2.0.0.GA.jar:jdom-2.0.1.jar:jsf-api-2.1.3-b02.jar:jsf-impl-2.1.3-b02.jar:jstl-1.2.jar:liferay-faces-bridge-api-3.1.1-ga2.jar:liferay-faces-bridge-impl-3.1.1-ga2.jar:liferay-faces-portal-3.1.1-ga2.jar:liferay-faces-util-3.1.1-ga2.jar:log4j.jar:Main.class:Main.java:ontimizeEN.jar:ontimizeWeb.jar:recaptcha4j-0.0.7.jar:util-bridges.jar:util-java.jar:util-taglib.jar:workflowEN.jar:portal-service-6.1.1.jar:tsafirma.jar:." es.tecnocom.tsafirma.AFirmaImpl $1 >> logPruebaSelladoTiempo.log && less -Ss logPruebaSelladoTiempo.log

tambien se puede poner al final en lugar de less: «tail -2», para mostrar solo el resultado

Hay que dar permisos, y ejecutar…

chmod 775 ejecuta.sh
./ejecuta.sh ficheroASellar.xml
javac classpath multiple jars

Spring AOP con XML

Tengo una clase que genera «id» de conexiones. Es necesario, para operar con la plataforma Cividas. Estoy intentando que el programador se abstraiga de abrir y cerrar conexiones. De esta manera en la parte aop:pointcut indico que clases y metodos se veran afectados.

	<bean id="cividasConnection" class="es.depontevedra.cividas.rmi.connect.CividasConnection">
		<property name="user" value="${cividas.server.user}" />
		<property name="pass" value="${cividas.server.pass}" />
		<property name="host" value="${cividas.server.host}" />
		<property name="port" value="${cividas.server.port}" />
		<property name="name" value="${cividas.server.name}" />
	</bean>
	<!-- AOP configuration -->
	<aop:config>
		<aop:aspect ref="cividasConnection">
			<aop:pointcut id="serviceMethod" expression="execution(* es.depontevedra.cividas.rmi.connect.service.*.*(..))" />
			<aop:before method="startSession" pointcut-ref="serviceMethod" />
			<aop:after method="stopSession" pointcut-ref="serviceMethod" />
			<aop:after-throwing method="stopSession" pointcut-ref="serviceMethod" />
		</aop:aspect>
	</aop:config>
Spring AOP con XML

testNG

Del ultimo post, hay un test con JUnit.
El mismo test pero con TestNG:

		<!-- en el pom.xml quitar la dependencia con JUnit y añadir-->
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>6.8.5</version>
			<scope>test</scope>
		</dependency>
package net.prietopalacios.josemanuel.aop.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

@ContextConfiguration("file:src/main/resources/spring.xml")
public class ServiceImplTest extends AbstractTestNGSpringContextTests {
	
	@Autowired
	Service service;

	@Test(threadPoolSize = 2, invocationCount = 2,  timeOut = 10000)
//	@Test(threadPoolSize = 2, invocationCount = 4)
	public void testDoSomething() {
		try {
			service.sendSomething();
			assertTrue(true);
		} catch (Exception e) {
			assertException(e);
		}
		
	}
	
	@Test(threadPoolSize = 2, invocationCount = 2,  timeOut = 10000)
	public void testThrowEsception() {
		try {
			service.sendEsception();
			assertTrue(true);
		} catch (Exception e) {
			assertException(e);
		}
	}

	private void assertException(Exception e) {
		if(e.getMessage() != null){
			assertTrue(false, e.getMessage());
		}else{
			assertTrue(false, e.getCause().getMessage());
		}
	}

}
testNG

Spring AOP start close connection con anotaciones

package net.prietopalacios.josemanuel.aop.service;

public interface Service {

	public void sendSomething();
	public void sendEsception() throws Exception;
	
}
package net.prietopalacios.josemanuel.aop.service;


public class ServiceImpl implements Service {

	public void sendSomething() {
		System.out.println("--------------------");
		System.out.println("I'm doing something.");
		System.out.println("--------------------");

	}

	public void sendEsception() throws Exception {
		throw new Exception("Exception");
	}

	@Override
	public String toString() {
		return "ServiceImpl []";
	}

}
package net.prietopalacios.josemanuel.aop;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class AopService {

	private Map<Integer, Integer> sessions;
	private Map<Integer, Integer> history;

	public AopService() {
		this.sessions = new HashMap<Integer, Integer>();
		this.history = new HashMap<Integer, Integer>();
	}
	
	@Before(value="(execution(* net.prietopalacios.josemanuel.aop.service.*.*(..)))")
	public void startsession(JoinPoint joinPoint) throws Exception {  
		int hashCode = joinPoint.hashCode();
		int session = startSession();
		startSession(hashCode, session);

		System.out.println("==================");
		System.out.println("BEFORE: ");
		System.out.println("hashCode: " + hashCode);
		System.out.println("session: " + session);
	}

	@AfterThrowing(value="(execution(* net.prietopalacios.josemanuel.aop.service.*.*(..)))", throwing="exception")
	public void afterThrowingStopSession(JoinPoint joinPoint, Exception exception) throws Exception {  
		int hashCode = joinPoint.hashCode();
		int session = sessions.get(hashCode);

		System.out.println("AFTERTHROWING: ");
		System.out.println("hashCode: " + hashCode);
		System.out.println("session: " + session);

		stopSession(hashCode, session);
	}

	@After(value="(execution(* net.prietopalacios.josemanuel.aop.service.*.*(..)))")  
	public void afterStopSession(JoinPoint joinPoint) throws Exception {  
		int hashCode = joinPoint.hashCode();
		if(!sessions.containsKey(hashCode)) return;
		int session = sessions.get(hashCode);

		System.out.println("AFTER: ");
		System.out.println("hashCode: " + hashCode);
		System.out.println("session: " + session);

		stopSession(hashCode, session);
	}

	private int startSession(){
		Random randomGenerator = new Random();
		return randomGenerator.nextInt(100);
	}

	private void startSession(int hashCode, int session) throws Exception{
		if(sessions.containsKey(hashCode)) {
			throw new Exception ("Ya existe la clave: " + hashCode);
		}
		sessions.put(hashCode, session);
		history.put(hashCode, session);
	}

	private void stopSession(int hashCode, int session) throws Exception{
		printMap();
		int remove = sessions.remove(hashCode);
		if(remove != session) throw new Exception("Imposible cerrar conexion");
	}
	
	private void printMap(){
		int n=1;
		for(Entry<Integer, Integer> entry: history.entrySet()){
			System.out.println(n++ + ".- (h)clave: " + entry.getKey() + ", valor:" + entry.getValue());
		}
		n=0;
		for(Entry<Integer, Integer> entry: sessions.entrySet()){
			System.out.println(n++ + ".- (s)clave: " + entry.getKey() + ", valor:" + entry.getValue());
		}
	}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

	<aop:aspectj-autoproxy />

	<bean id="service" class="net.prietopalacios.josemanuel.aop.service.ServiceImpl" />
	<bean id="aop" class="net.prietopalacios.josemanuel.aop.AopService" />

</beans>  
package net.prietopalacios.josemanuel.aop.service;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring.xml")
public class ServiceImplTest {
	
	@Autowired
	Service service;

	@Test
	public void testDoSomething() {
		try {
			service.sendSomething();
			service.sendSomething();
			assertTrue(true);
		} catch (Exception e) {
			if(e.getMessage() != null){
				assertTrue(e.getMessage(), false);	
			}else{
				assertTrue(e.getCause().getMessage(), false);
			}
		}
		
	}
	
	@Test
	public void testThrowEsception() {
		try {
			service.sendEsception();
			assertTrue(true);
		} catch (Exception e) {
			if(e.getMessage() != null){
				assertTrue(e.getMessage(), false);	
			}else{
				assertTrue(e.getCause().getMessage(), false);
			}
		}
	}

}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>net.prietopalacios.josemanuel</groupId>
	<artifactId>aop</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>aop_example</name>

	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.0.5.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjtools</artifactId>
			<version>1.7.3</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>2.2</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>3.0.5.RELEASE</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

</project>
Spring AOP start close connection con anotaciones