Shared Library jar are not loaded by Liberty - websphere-liberty

I have spring MVC application which uses Spring 4.I deploying my application in Liberty 16.0.0.3.I have below server.xml configuration.
<server description="Default Server">
<featureManager>
<feature>webProfile-7.0</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<variable name="defaultHostName" value="localhost"/>
<keyStore id="defaultKeyStore" password="mypassword" />
<!-- Define an Administrator and non-Administrator -->
<basicRegistry id="basic">
<user name="admin" password="mypassword"/>
<user name="nonadmin" password="mypassword"/>
</basicRegistry>
<!-- Assign 'admin' to Administrator -->
<administrator-role>
<user>admin</user>
</administrator-role>
<webContainer deferServletLoad="false"/>
<applicationManager autoExpand="true"/>
<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<variable name="defaultHostName" value="localhost"/>
<library id="global">
<fileset dir="${shared.config.dir}/lib/global" includes="*.jar" />
</library>
<application type="war" location="testliberty.war" autoStart="true" context-root="/Spring4">
<classloader commonLibraryRef="global" delegation="parentLast"/>
</application>
</server>
I have placed all spring specific jar's in below location.
usr\shared\config\lib\global
Anthoer option
server\lib\global
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.liberty.sample</groupId>
<artifactId>TestLiberty</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>HelloWorld</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<org.springframework-version>4.3.0.RELEASE</org.springframework-version>
<runtime.scope>provided</runtime.scope>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
<scope>${runtime.scope}</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>${runtime.scope}</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>${runtime.scope}</scope>
</dependency>
</dependencies>
<build>
<finalName>HelloWorld</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>testliberty</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
But none of this option is working.Server is not loading these jar's due to this Spring application context is not getting loaded.But same application is working fine if I package all the jar's in WEB-INF/lib folder.

Related

Spring boot + Primefaces modular app don't see xhtml page

I have an modular application Spring boot + Primefaces project and when I start it, the server does not see the page. Project structure:
app_module
--src
---main
----java
-----org.example.model (where placed entities, and beans for Jsf and main Spring Boot class)
--pom.xml
presentation_module
--src
---main
----webapp
-----WEB-INF
------faces-config.xml
------web.xml
-----install.xhtml
--pom.xml
pom.xml(parent)
app_module 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">
<parent>
<artifactId>org.vozup.givemeroom</artifactId>
<groupId>GiveMeRoom</groupId>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>givemeroom-app</artifactId>
<packaging>jar</packaging>
<build>
<finalName>app</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
presentation_module 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">
<parent>
<artifactId>org.vozup.givemeroom</artifactId>
<groupId>GiveMeRoom</groupId>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>givemeroom-presentation</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>GiveMeRoom</groupId>
<artifactId>givemeroom-app</artifactId>
<version>0.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.faces/jsf-api -->
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</plugin>
</plugins>
</build>
</project>
parent 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>GiveMeRoom</groupId>
<artifactId>org.vozup.givemeroom</artifactId>
<packaging>pom</packaging>
<version>0.0.1</version>
<modules>
<module>presentation_module</module>
<module>app_module</module>
</modules>
<profiles>
<profile>
<id>prod</id>
<dependencies>
<!-- postgres java connector for PROD-->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>dev</id>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 for DEV-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<properties>
<java.version>1.8</java.version>
<junit.version>4.12</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<!-- display active profile in compile phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>show-profiles</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>modwebapp</display-name>
<servlet>
<servlet-name>Faces Sevlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Sevlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>install.xhtml</welcome-file>
</welcome-file-list>
</web-app>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0">
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>goToInstallPage</from-outcome>
<to-view-id>/install.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
</faces-config>
When I try to get to the page localhost:8080/install.xhtml I get a Whitelabel Error Page error 404.
Maybe I don’t collect the project properly. Please help, thank you!

How to execute multiple class defined under test method in testng.xml from POM.xml

Below is my testng.xml file code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SaferSystem" >
<parameter name="dev_URL" value="http://localhost:8383/" />
<test name="ChromeTest">
<parameter name="browser" value="Chrome" />
<parameter name="username" value="jayeshdp#weblineindia.com" />
<parameter name="password" value="System123" />
<classes>
<class name="com.safer.login.LoginTest" />
<class name="com.safer.login.DashboardTest"/>
</classes>
</test>
And below is my POM.xml code:
<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>SaferSystem</groupId>
<artifactId>SaferMavenProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SaferMavenProject</name>
<url>http://maven.apache.org</url>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
</project>
I want to execute "DashboardTest" java file but when I add "DashboardTest" line code does not executes. But if I keep only "LoginTest" class then code executes properly. How can I solve this issue as I have multiple classes to add under test.Please help as I am quite new for Maven and working on Maven project. Thanks in advance.

Liberty profile not able to detect Spring Boot componentscan annotation and not loading application context

I am deploying Spring Boot web application in Liberty 16.0.0.3.Have provided all dependency scope as provided and configured global shared library.But when I start the application Liberty not been able to load application context.
My configuration as below.
My 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.myapp.testapp</groupId>
<artifactId>testsharedlib</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>testsharedlib</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<runtime.scope>provided</runtime.scope>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>${runtime.scope}</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
<scope>${runtime.scope}</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- <version>2.3</version> -->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
<!-- <failOnMissingWebXml>false</failOnMissingWebXml> -->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
<archive>
<manifest>
<mainClass>com.myapp.testapp.Appconfig</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<DisableIBMJAXWSEngine>true</DisableIBMJAXWSEngine>
<Class-Path>conf</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Liberty server.xml
<server description="Default Server">
<featureManager>
<feature>webProfile-7.0</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<library id="global">
<fileset dir="${server.config.dir}/lib/jars" includes="*.jar"/>
</library>
<application context-root="HelloWorld" location="text-1.0.0-SNAPSHOT.war">
<classloader commonLibraryRef="global" delegation="parentFirst"/>
</application>
<!-- Define the host name for use by the collective.
If the host name needs to be changed, the server should be
removed from the collective and re-joined. -->
<variable name="defaultHostName" value="localhost"/>
<keyStore id="defaultKeyStore" password="adminpwd"/>
<!-- Define an Administrator and non-Administrator -->
<basicRegistry id="basic">
<user name="admin" password="adminpwd"/>
<user name="nonadmin" password="nonadminpwd"/>
</basicRegistry>
<!-- Assign 'admin' to Administrator -->
<administrator-role>
<user>admin</user>
</administrator-role>
<webContainer deferServletLoad="false"/>
<applicationManager autoExpand="true"/>
<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<logging consoleLogLevel="INFO" traceSpecification="*=info:com.ibm.ws.classloading.*=ALL"/>
</server>
The reason why this works with dependencies in WEB-INF/lib and not in a global shared lib is because the servlet that initializes your Spring application (org.springframework.web.servlet.DispatcherServlet) is coming from one of the jar dependencies. Liberty will only scan the web context root (i.e. WEB-INF/*) for servlet classes. It will not scan shared libraries for servlet classes.
As you found out in your other answer, the only way to link up a servlet coming from a jar in a shared lib is to explicitly declare it in web.xml (since Liberty will not auto-scan for it like it does for classes or jars in WEB-INF/*.
To confirm this, I wrote a simple servlet:
#WebServlet("/LibServlet")
public class LibServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.getWriter().append("Served at: ").append(request.getContextPath());
}
}
Then I packaged this servlet into servletLib.jar. When I provided this lib to my application using a shared library, I was not able to access the servlet at http://localhost:9080/testapp/LibServlet. However, when I moved servletLib.jar into a WEB-INF/lib then the servlet was accessible.
I am able to make it work by providing WEB-INF/web.xml in Liberty with global shared Library. Find below sample configuration.
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.myapp.testapp</groupId>
<artifactId>testsharedlib</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>testsharedlib</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<runtime.scope>provided</runtime.scope>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>${runtime.scope}</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
<scope>${runtime.scope}</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
server.xml
<featureManager>
<feature>webProfile-7.0</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<library id="global">
<fileset dir="${server.config.dir}/lib/jars" includes="*.jar"/>
</library>
<application context-root="HelloWorld" location="text-1.0.0-SNAPSHOT.war">
<classloader commonLibraryRef="global" delegation="parentLast"/>
</application>
<!-- Define the host name for use by the collective.
If the host name needs to be changed, the server should be
removed from the collective and re-joined. -->
<variable name="defaultHostName" value="localhost"/>
<keyStore id="defaultKeyStore" password="adminpwd"/>
<!-- Define an Administrator and non-Administrator -->
<basicRegistry id="basic">
<user name="admin" password="adminpwd"/>
<user name="nonadmin" password="nonadminpwd"/>
</basicRegistry>
<!-- Assign 'admin' to Administrator -->
<administrator-role>
<user>admin</user>
</administrator-role>
<webContainer deferServletLoad="false"/>
<applicationManager autoExpand="true"/>
<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<logging consoleLogLevel="INFO" traceSpecification="*=info:com.ibm.ws.classloading.*=ALL"/>
</server>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>pctext</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.myapp.testpkg.ApplicationConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
ApplicationConfig.java
#SpringBootApplication(scanBasePackages={"com.myapp.testpkg"})
public class ApplicationConfig {
public static void main(String[] args) {
SpringApplication.run(ApplicationConfig.class, args);
}
}

Maven - build a manifest.mf with customized Class-Path

I am using Maven to build an EAR project with 20+ artifacts and ~30 3rd party artifacts.
The EAR structure looks like this
EAR
+-project-artifact-1
+-project-artifact-2
...
+-project-artifact-n
+-lib/
| +-3rd-party-lib-1
| +-3rd-party-lib-2
| ...
| \-3rd-party-lib-n
\-META-INF/
packaging works fine.
My problem is with the customization of the Class-Path for the MANIFEST.MF
I want to use Mavens feature to create the MANIFEST.MF for me by using
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
I know I can use the classpathPrefix to set a prefix, but this prefix will be added to all dependencies, regardless of their location.
For technical reasons, I cannot put all my JAR type artifacts in the lib folder.
The only workaround for this would be to set my project-artifact dependencies to scope provided and add them manually to the class path with manifestEntries.
I do not like this workaround, as it is hard to maintain and effectively kills the transitivity of my dependencies (and I want to keep that).
I found this example for a custom class-path but I don't see how I can use it for my purpose. My idea was to use a property to manipulate the class-path, but it seems that you can only use certain attributes of the artifact as variables.
Is there any other way to build the CP (except using a manually maintained MF or manually maintaining the CP entries in the poms)?
this is what my parent pom looks like (shortened):
<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.my.app</groupId>
<artifactId>build-parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<name>build parent</name>
<description>
</description>
<repositories>
<repository>
<id>myapp-internal</id>
<url>file:///${user.home}/.m2/repository</url>
<releases>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
</repositories>
<properties>
<!-- variables -->
<!-- myapp -->
<myapp.version>0.1</myapp.version>
<myapp.encoding>Cp1252</myapp.encoding>
<!-- config variables -->
<directory.target>../myapp_build/target</directory.target>
<version.ejb>3.1</version.ejb>
<!-- 3rd party lib versions -->
<version.slf4j>1.7.10</version.slf4j>
<!-- maven plugin versions -->
<version.plugin.buildhelper>1.3</version.plugin.buildhelper>
<version.plugin.maven.assambley>2.2.1</version.plugin.maven.assambley>
<version.plugin.maven.compiler>3.1</version.plugin.maven.compiler>
<version.plugin.maven.ear>2.9.1</version.plugin.maven.ear>
<version.plugin.maven.ejb>2.3</version.plugin.maven.ejb>
<version.plugin.maven.jar>2.4</version.plugin.maven.jar>
<version.plugin.maven.war>2.4</version.plugin.maven.war>
<!-- settings -->
<project.build.sourceEncoding>${myapp.encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${myapp.encoding}</project.reporting.outputEncoding>
</properties>
<!-- define default dependency details -->
<dependencyManagement>
<dependencies>
<!-- myapp dependencies -->
<!-- com.my.app -->
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact1</artifactId>
<version>${myapp.version}</version>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact2</artifactId>
<version>${myapp.version}</version>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_ejb</artifactId>
<version>${myapp.version}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_web</artifactId>
<version>${myapp.version}</version>
<type>war</type>
</dependency>
<!-- 3rd party dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.slf4j}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>${version.slf4j}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<!-- use Eclipse style structure -->
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<!-- target -->
<directory>${directory.target}</directory>
<!-- define default plugin settings -->
<pluginManagement>
<plugins>
<!-- assambley -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${version.plugin.maven.assambley}</version>
</plugin>
<!-- build helper -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${version.plugin.buildhelper}</version>
</plugin>
<!-- compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.plugin.maven.compiler}</version>
<configuration>
<source>${version.java}</source>
<target>${version.java}</target>
</configuration>
</plugin>
<!-- ear -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.plugin.maven.ear}</version>
</plugin>
<!-- ejb -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>${version.plugin.maven.ejb}</version>
<configuration>
<ejbVersion>${version.ejb}</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<!-- jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${version.plugin.maven.jar}</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</archive>
</configuration>
</plugin>
<!-- war -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${version.plugin.maven.war}</version>
<configuration>
<!-- use provided web.xml -->
<webXml>WebContent/WEB-INF/web.xml</webXml>
<!-- ressources location -->
<warSourceDirectory>WebContent</warSourceDirectory>
<!-- build a skinny WAR -->
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
this is my (shortened) pom for the EAR:
<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>
<parent>
<groupId>com.my.app</groupId>
<artifactId>build-parent</artifactId>
<version>0.1</version>
<relativePath>../myapp_build</relativePath>
</parent>
<groupId>com.my.app</groupId>
<artifactId>myapp_application_EAR</artifactId>
<version>${myapp.version}</version>
<description />
<packaging>ear</packaging>
<dependencies>
<!-- myapp dependencies -->
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_web</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_ejb</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact1</artifactId>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact2</artifactId>
</dependency>
<!-- 3rd party dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<generateApplicationXml>true</generateApplicationXml>
<!-- skinny WAR configuration see WAR project POM -->
<skinnyWars>true</skinnyWars>
<modules>
<webModule>
<groupId>com.my.app</groupId>
<artifactId>myapp_web</artifactId>
<contextRoot>myapp_web</contextRoot>
</webModule>
<ejbModule>
<groupId>com.my.app</groupId>
<artifactId>myapp_ejb</artifactId>
</ejbModule>
<!-- 3rd party libs go to lib/ -->
<jarModule>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<bundleDir>lib/</bundleDir>
<includeInApplicationXml>false</includeInApplicationXml>
</jarModule>
<jarModule>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<bundleDir>lib/</bundleDir>
<includeInApplicationXml>false</includeInApplicationXml>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>

EclipseLink + Maven: java.lang.NoClassDefFoundError: javax/persistence/Persistence

My Persistence.xml is as follows:
<persistence-unit name="SARMPersistentUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>edu.deakin.sarms.model.StudentAccount</class>
<class>edu.deakin.sarms.model.LecturerAccount</class>
<class>edu.deakin.sarms.model.Unit</class>
<class>edu.deakin.sarms.model.Enrollment</class>
<class>edu.deakin.sarms.model.Attendance</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://xx.yy.ss:3306/t2"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="xx"/>
<property name="javax.persistence.jdbc.password" value="ee"/>
<property name="eclipselink.ddl-generation" value="drop-create-tables"/>
</properties>
</persistence-unit>
pom.xml is as follows:
<?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>edu.deakin.sarms</groupId>
<artifactId>sarms2</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>oss.sonatype.org</id>
<name>OSS Sonatype Staging</name>
<url>https://oss.sonatype.org/content/groups/staging</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.persistence</groupId>
<artifactId>commonj.sdo</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
<fork>true</fork>
<meminitial>128M</meminitial>
<maxmem>512M</maxmem>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>edu.deakin.sarms.service.SarmsControl</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Still I am getting "java.lang.NoClassDefFoundError: javax/persistence/Persistence", on the line:
public static EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("SARMPersistentUnit");
Can anyone please suggest what am I doing wrong?
Cheers
Ayesha
I was doing a mvn clean install and then java -jar . Then I used the command mentioned by #ajozwk in the comment, but I had another issue, the persistence.xml file was under src/main/ instead of src/main/resources. So now my problem is fixed!

Resources