I have developed a command line application (it's a batch) using Spring framework and I have the following problem
If I execute it inside Ecipse it works fine, as I expected.
Then I have created an executable jar file using this Maven plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.myCompany.main.MainFlussoORolIspb</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-${project.version}-executable</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
So the jar file is created, now the problem is that when I try to execute it into the DOS shell, by: java -jar BATCH-FLUSSO-OROLISPB-0.0.1-SNAPSHOT-executable.jar I obtain this exception:
C:UsersAndreaDocumentsMyCompany>java -jar BATCH-FLUSSO-OROLISPB-0.0.1-SNAPSHOT-executable.jar
log4j:WARN No appenders could be found for logger (com.myCompany.main.MainFlussoORolIspb).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.aotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:298)
at org.springframework.context.aotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
at org.springframework.context.aotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
at org.springframework.context.aotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:230)
at org.springframework.context.aotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:153)
at org.springframework.context.aotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130)
at org.springframework.context.aotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcess
or.java:285)
at org.springframework.context.aotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostPr
ocessor.java:223)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:63
0)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at com.myCompany.main.MainFlussoORolIspb.esecuzione(MainFlussoORolIspb.java:34)
at com.myCompany.main.MainFlussoORolIspb.main(MainFlussoORolIspb.java:20)
Why in Eclipse it works fine but when I perform the JAR it give me the previous error message? What am I missing?
Reading the previous stacktrace it seems that the error is in the main() method (or something like this), this is the class containing the main() method:
public class MainFlussoORolIspb {
private Logger log = Logger.getLogger(MainFlussoORolIspb.class);
private PucManager puc;
public static void main(String[] args) {
new MainFlussoORolIspb().esecuzione();
}
private void esecuzione() {
log.info("BATCH-FLUSSO-OROLISPB STARTED");
log.info("Initializing Spring context.");
//javax.swing.JOptionPane.showInputDialog("Inserisci percorso file da generare");
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
ConfigurableEnvironment conf = (ConfigurableEnvironment) applicationContext.getEnvironment();
conf.setActiveProfiles("PROD");
applicationContext.load("/META-INF/applicationContext.xml");
applicationContext.refresh();
log.info("Spring context initialized.");
puc = (PucManager)applicationContext.getBean("pucManager");
log.info("PucManager correttamente reperito dal contesto");
System.out.println(puc.testMethod());
List<RolBean> listRolBean = puc.getListaRolBean();
System.exit(0);
}
}
