0

I have an application which leverages PrimeFaces, elastic search,Spring boot.

Following is it's pom.xml,

<?xml version="1.0" encoding="UTF-8"?>
<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>com.acn.hps.aops.demo</groupId>
    <artifactId>PSCommandCenter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>CommandCentre</name>
    <description>Command Center Application</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.code.geocoder-java</groupId>
            <artifactId>geocoder-java</artifactId>
            <version>0.16</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>

        <!-- Primefaces -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.2</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>all-themes</artifactId>
            <version>1.0.10</version>
        </dependency>

        <dependency>
            <groupId>org.atmosphere</groupId>
            <artifactId>atmosphere-runtime</artifactId>
            <version>2.3.4</version>
        </dependency>

        <!-- JSF dependencies -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.8</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.8</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Elastic Search dependencies -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>1.7.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
          <groupId>com.opencsv</groupId>
          <artifactId>opencsv</artifactId>
          <version>3.7</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>primefaces</id>
            <url>http://repository.primefaces.org</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Following is its spring configuration,

@SpringBootApplication
public class CommandCentreApplication extends WebMvcConfigurerAdapter{
    public static void main(String[] args) {
        SpringApplication.run(CommandCentreApplication.class, args);
    }
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/home.jsf");
    }
    @Bean
    ServletRegistrationBean facesServletRegistration() {
        return new ServletRegistrationBean() {
            @Override
            public void onStartup(ServletContext servletContext)
                    throws ServletException {
                FacesInitializer facesInitializer = new FacesInitializer();
                facesInitializer.onStartup(Collections.singleton(CommandCentreApplication.class),
                        servletContext);
                servletContext.setInitParameter("primefaces.THEME", "redmond");
                servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "0");
                servletContext.setInitParameter("facelets.SKIP_COMMENTS", "true");
            }
        };
    }
    @Bean
    ServletRegistrationBean pushServletRegistration(){
        ServletRegistrationBean pushServlet = new ServletRegistrationBean(new PushServlet(), "/primepush/*");
        pushServlet.addInitParameter("org.atmosphere.annotation.packages", "org.primefaces.push");
        pushServlet.addInitParameter("org.atmosphere.cpr.packages", "com.acn.hps.aops.demo.map.service.channel");
        pushServlet.setAsyncSupported(true);
        pushServlet.setLoadOnStartup(0);
        pushServlet.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return pushServlet;
    }
}

and my elastic search's configuration,

@Bean
 public Client client(){
     TransportClient client= new TransportClient();
     TransportAddress address = new InetSocketTransportAddress(PropertiesLoader.esIP, PropertiesLoader.esPort);
     client.addTransportAddress(address);
     return client;
 }

This same application runs as expected when I execute it from my IDE (Eclipse) but when I execute the application from its jar then I am getting the following exception ,

java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_45].

I searched for this exception and I found that jstl's jar is added to avoid this error. But I already have jstl's jar in tomcat's jar. And also if this is the problem then I should be getting the same exception while executing from my IDE.

You can refer this github code which i used as outline for my application. I am facing the same issue in this also.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
BhaskerYadav
  • 569
  • 3
  • 24
  • @balusC its not duplicate as I have mentioned this code is working correctly in IDE its when i am creating jar via spring boot and executing jar I am facing this problem. And also I tried adding the mentioned JSTL its still not working. – BhaskerYadav Mar 29 '16 at 11:45
  • After looking at the suggestion I added the mentioned jar's dependency in pom and I got this warning "Duplicating managed version 1.2 for jstl pom.xml /PSCommandCenter line 91 Maven pom Loading Problem" and this resource not found exception along with this message in console , ' JSF1091: No mime type could be found for file /home.jsp. To resolve this, add a mime-type mapping to the applications web.xml.' and also my question is if my application is working with same resource in IDE then why its jar isn't? – BhaskerYadav Mar 29 '16 at 11:52
  • you can have a look at the github's link . It is having same project outline which I am using and its small one also, so that u can replicate this issue. Thanks for ur response. – BhaskerYadav Mar 29 '16 at 12:02

1 Answers1

-1

When using spring-boot-starter as a parent, running

mvn clean install

should produce a fat jar (that means all dependencies are copied into that jar). More informations can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html

Maybe this part in the spring-boot-starter plugin within the pom.xml

<configuration>
    <executable>true</executable>
</configuration>

is messing with this. Try to remove that part and build the jar again.

enem.dev
  • 124
  • 4
  • I added this code after, prior to this also it wasn't working. You can refer to the git code I linked in my edited question. – BhaskerYadav Mar 29 '16 at 10:35