Exclude jar from war Maven 3 - war

We need to exclude few jars from war ...we are using maven 3 in weblogic.
I tried
<packagesourceexludes>...and <warsournceexludes..>
but didn't work.
Any other way to do this.
Thanks
Vijay

<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
So doesn't need to exclude from every dependency..
This solved my problem...Thanks for all your answer...

You need to use <packagingExcludes> as documented here. Cut/pasting the example for reference...
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>

The usual way to exclude dependencies is shown here. If that's what you've tried, make sure, no other dependency includes the excluded jar (which can be checked by mvn dependency:tree).

Related

Could not find artifact javafx-packager:javafx-packager:

This is my pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ginkgo</groupId>
<artifactId>csgo-cfg-helper-client</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>16</maven.compiler.release>
<javafx.version>16</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.maven.plugin.version}</version>
<configuration>
<jlinkImageName>csgo_cfg_helper</jlinkImageName>
<launcher>launcher</launcher>
<mainClass>com.ginkgo.csgo.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<mainClass>com.ginkgo.csgo.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
My Operating System: MacOs Big Sur 11.4
JDK: openjdk-16.0.1
I want to make a .dmg or .pkg file using command mvn clean jfx:native, however, it doesn't work.
[ERROR] Failed to execute goal com.zenjava:javafx-maven-plugin:8.8.3:jar (jar) on project csgo-cfg-helper-client: Execution jar of goal com.zenjava:javafx-maven-plugin:8.8.3:jar failed: Plugin com.zenjava:javafx-maven-plugin:8.8.3 or one of its dependencies could not be resolved: Could not find artifact javafx-packager:javafx-packager:jar:1.8.0_20 at specified path /Users/hll/Library/Java/JavaVirtualMachines/openjdk-16.0.1/Contents/Home/../lib/ant-javafx.jar -> [Help 1]
Is it Java Version too high? jLink work well and generate module success.
How should i do? This is my first time to bulid a JavaFX project. I find the same question in stackoverflow, but no useful answer.Thanks for your help.
You seem to follow an ancient tutorial. Just start with the official docs and not some crap pulled from the internet. https://openjfx.io/openjfx-docs/ And for packaging you app have a look here: https://docs.oracle.com/en/java/javase/16/jpackage

Payara Micro: How to log with slf4j (or log4j2)?

I'm using Payara Micro (bundled ueberjar) for a recent project, but I have difficulties with logging. Seems like Payara Micro uses JUL by default, which does not suit my needs. I'd like to use Log4J 2 instead, preferably through slf4j. Unfortunately, I couldn't find much information. To start with, I'd like refer to the following link...
https://blog.payara.fish/the-basics-of-logging-in-payara-server
... which says: "Payara Micro can also be adjusted to use other logging frameworks like Logback and Log4J2." Sounds great, but the only source that deals with that matter seems to be the following example project: https://github.com/hei1233212000/payara-micro-log4j2. Yet it is from 2017 and seems to be outdated as it doesn't use the payara micro maven plugin. Still, I guess the point is:
add the necessary logging jars to the bundle
adjust Manifest file by adding the jars to the classpath
use the SLF4JBridgeHandler for Payara Micro
I tried my luck adding the jars as customJars via the payara micro maven plugin, which indeed resulted in a bundled jar containing those libs under MICRO-INF/lib. From what I read, the jars should also be on classpath, though they don't appear in the Manifest file. Also, I added the logging.properties tih the following simple content under src/main/resources:
handlers=org.slf4j.bridge.SLF4JBridgeHandler
Now, if I run the bundled jar, it says Can't load log handler "org.slf4j.bridge.SLF4JBridgeHandler", followed by an ugly stacktrace. Yet the class org.slf4j.bridge.SLF4JBridgeHandler is in one of the jars I added. I already experimented with the groovy script from the example I linked above to edit the Manifest file, but I couldn't figure out how to set it up properly. I mean, the script worked and I get an edited Manifest file, but it is not added to the bundled jar - I guess my timing is bad. Not to mention that this is kind of hackish as the author of the example said.
Interestingly, if I don't add the logging.properties to the jar, thus leaving Payara Micros logging setup untouched, I can reroute logging output from 3rd party libraries (such as hibernate) coming with Payara Micro while its own logs are logged to the console. Yet that's not my goal as I am more interested in the latter logs.
So, I'd be thankful if someone could give me a hand. Thanks for reading. For completeness, here is my pom.xml (I am using the package profile, the other is for cucumber tests only):
<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>de.kepes.payara-micro</groupId>
<artifactId>payara-micro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<skipTests>true</skipTests>
<payara-micro.version>5.194</payara-micro.version>
<payara-micro.plugin.version>1.0.6</payara-micro.plugin.version>
<jakarta.version>8.0.0</jakarta.version>
<maven-failsafe.plugin.version>2.22.2</maven-failsafe.plugin.version>
<cucumber.version>5.4.0</cucumber.version>
<websocket.version>1.4.0</websocket.version>
<log4j.version>2.13.0</log4j.version>
<slf4j.version>1.7.30</slf4j.version>
</properties>
<profiles>
<profile>
<id>package</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>fish.payara.maven.plugins</groupId>
<artifactId>payara-micro-maven-plugin</artifactId>
<version>${payara-micro.plugin.version}</version>
<executions>
<execution>
<id>bundle</id>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
<execution>
<id>start</id>
<goals>
<goal>start</goal>
</goals>
</execution>
</executions>
<configuration>
<useUberJar>true</useUberJar>
<deployWar>true</deployWar>
<payaraVersion>${payara-micro.version}</payaraVersion>
<customJars>
<customJar>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</customJar>
<customJar>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</customJar>
<customJar>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</customJar>
<customJar>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</customJar>
<customJar>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</customJar>
</customJars>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>test</id>
<properties>
<skipTests>false</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>fish.payara.maven.plugins</groupId>
<artifactId>payara-micro-maven-plugin</artifactId>
<version>${payara-micro.plugin.version}</version>
<executions>
<execution>
<id>pre-integration-payara</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>post-integration-payara</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<payaraVersion>${payara-micro.version}</payaraVersion>
<deployWar>true</deployWar>
<contextRoot>/</contextRoot>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>${jakarta.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>${websocket.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
this isn't possible just by adding logging libraries as custom JARs as logging is initialized before those libraries are loaded.
However, there's a solution how to use alternative logging libraries. You need to run Payara Micro in a different way. If you put it on the classpath and run the Payara Micro main class directly, you can put custom logging libraries on the classpath too and they will be picked up at boot time, before logging is initialized. If you have payara-micro.jar, slf4j.jar, log4j.jar and jul-to-slf4j.jar in the current directory, you can launch Payara Micro like this:
java -cp ./payara-micro.jar:slf4j.jar:log4j2.jar:jul-to-slf4j.jar fish.payara.micro.PayaraMicro some.war
Alternatively, you can move those logging JARs to a subdirectory lib and shorten the command line:
java -cp "./payara-micro.jar:lib/*" fish.payara.micro.PayaraMicro some.war
You can pass the same arguments to the PayaraMicro class which are accepted by the Payara Micro JAR.

class file for javax.servlet.ServletException not found [duplicate]

I'm trying to include Spring Security to my web project, i'm following this tutorial http://docs.spring.io/spring-security/site/docs/current/guides/html5//helloworld.html
I've done everything in the tutorial with the given maven project and works fine. But when i'm trying to include it to my project a compilation error appear. Specifically when i extends from AbstractSecurityWebApplicationInitializer appear the given error
Multiple markers at this line
The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files
The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files
The POM.xml
<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>spring.primefaces</groupId>
<artifactId>primefaces.testwebapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringPrimefacesWebApp</name>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JSF 2.2 core and implementation -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.11</version>
</dependency>
<!-- Prime Faces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
</dependency>
<!-- Spring security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.1.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Thanks for the help!
Using mvn clean install -U
Just add the javax.servlet API to the compile time dependencies. You don't need to include it in the build, it's already provided by the target servlet container.
Your current pom suggests that you're deploying to a barebones servlet container (Tomcat, Jetty, etc) instead of a full fledged Java EE application server (WildFly, TomEE, GlassFish, Liberty, etc), otherwise you'd have run into classloading-related trouble by providing JSF along with the webapp instead of using the container-provided one.
In that case, adding the below dependency should do for a Servlet 3.1 container like Tomcat 8:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Or if you're actually targeting an older Servlet 3.0 container like Tomcat 7, change the <version> to 3.0.1 (note: there's no 3.0 due to a mistake on their side).
If you happen to actually deploy to a Java EE 7 application server like WildFly 8, use the below dependency instead. It covers the entire Java EE API, including javax.servlet (and javax.faces, so you'd then remove those individual JSF API/impl dependencies):
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
Also here, if you're targeting an older Java EE 6 application server like JBoss AS 7, change the <version> to 6.0.
See also:
How to properly configure Jakarta EE libraries in Maven pom.xml for Tomcat?
This worked for me: if above supplied solution doesnt work
Project > Properties > Java Build Path > Libraries > Add library from library tab > Choose server runtime > Next > choose Apache Tomcat v 7.0> Finish > Ok
another way if you working on eclipse ide please open the project folder select Properties and click maven shows the view 'Active Maven Profiles(comma separated)'please input "dev"..after refresh problem solved
try setting the updated parent, like this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath></relativePath>
</parent>
this solved for me.
What helped for me was deleting the repository in directory .m2
and after deleting run maven: package

Compiling multiple .as files using Maven

I am having issues getting maven to do a simple clean install I am getting the following error:
Failed to execute goal org.sonatype.flexmojos:flexmojos-maven-plugin:3.8:compile-swf (default-compile-swf) on project flex: Source file not expecified and no default found! -> [Help 1]
I was following the tutorial on this site: Adobe Developer Connection - Flex and Maven
I have all of my .as files located in: src/main/flex/ but the problem is that I don't have a Main class, these are all basically interfaces so I can't just choose one of them to be the source file.
I have Eclipse installed as well, and it is yelling at me for the plugin part of the POM, saying:
Multiple annotations found at this line:
- Plugin execution not covered by lifecycle configuration: org.sonatype.flexmojos:flexmojos-maven-plugin:
3.8:compile-swf (execution: default-compile-swf, phase: compile)
- Plugin execution not covered by lifecycle configuration: org.sonatype.flexmojos:flexmojos-maven-plugin:
3.8:test-compile (execution: default-test-compile, phase: test-compile)
So I am not sure if this is related or not, but I have tried to copy/paste the code from the link above verbatim but I still get that error and the guy never mentions anything about it, so perhaps it's just a bug in the maven plugin in Eclipse.
Here is my POM.xml file:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>flex</artifactId>
<name>flex</name>
<packaging>swf</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>3.6.0.16995</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/flex</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>3.6.0.16995</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
I am open to ANY ideas on how to get this to compile these .as files. Thank you!
Edit: Okay I figured it out. I changed the packaging from swf to swc and it works. So very sad.
I converted the package from swf to swc and it worked like a champ. Hopefully this helps someone in the future.
you need the configuration tag so flexmojos knows where to start the build. (default application, or main class)
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<configuration>
<sourceFile>Module.mxml</sourceFile>
</configuration>
<version>3.6.0.16995</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>

Flyway not finding my sql migrations in db/migration

The error:
[ERROR] com.googlecode.flyway.core.api.FlywayException: Unable to determine URL for classpath location: db/migration (ClassLoader: ClassRealm[plugin>com.googlecode.flyway:flyway-maven-plugin:2.1.1, parent: sun.misc.Launcher$AppClassLoader#43be2d65])
I followed the quickstart, so I'm not really doing anything complex yet.
pom.xml
<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.cpt.migrations</groupId>
<artifactId>cpt_migrations</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cpt_migrations</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.24</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<user>root</user>
<password></password>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/cpt</url>
</configuration>
</plugin>
</plugins>
</build>
</project>
And my folder structure is the prescribed PROJECT_ROOT/src/main/resources/db/migration/V1__Base_version.sql:
I get the error when, from the PROJECT_ROOT, I execute:
mvn flyway:migrate
Don't forget to call compile first, to make sure the resources are copied over.
In my case I had to explicitely set
flyway.locations=classpath:db/migration
in my application.properties (Spring Boot) for it to work.
in my case this error was caused as package with name db.migration was created
instead of db -> migration
It has to be compiled:
mvn compile flyway:migrate
You may use
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
<execution>
<id>clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
in
<plugin>..</plugin>
and then just mvn compile is needed for execution of migrate task
In my case IntelliJ Idea created a folder db.migration instead of two separate folders db and migration inside
Execute mvn command from directory where target dir is located.

Resources