java.util.zip.ZipException: duplicate entry: META_INF/LICENSE.txt - java

This is my first time using Java Web Start. This is for a demo version of my application. I have uploaded the JAR to my server, and created a JNLP file. When I run the file locally, I get the exception shown below.
This was the reference I was reading, and below is my JNLP file.
DerbyPro.jnlp
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>Derby Pro</title>
<vendor>Neon Orb</vendor>
<icon href="http://neonorb.com/images/derby-pro/derby-pro-icon-hd.png"/>
<offline-allowed/>
</information>
<resources>
<j2se version="1.8+" href=
"http://neonorb.com"/>
<jar href="http://neonorb.com/clientportal/derby-pro-demo.jar"
main="true" />
</resources>
<application-desc
name="Derby Pro"
main-class="com.neonorb.derbypro.main.DerbyPro"
width="300"
height="300">
</application-desc>
<update check="background"/>
</jnlp>
Here is my build.gradle file being called like this: ./gradlew -Pversion=0.0.0 -Pdemo=true fatJar
group 'com.neonorb'
apply plugin: 'java'
sourceCompatibility = 1.8
project.description = 'Derby Pro is pinewood derby management software.'
//create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Version': version,
'Main-Class': 'com.neonorb.derbypro.main.DerbyPro',
'Demo': demo
}
baseName = project.name
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
repositories {
mavenCentral()
maven {
url "http://www.sparetimelabs.com/maven2"
}
mavenLocal()
}
dependencies {
compile files('dfalex-0.9.2.jar')
compile 'com.neonorb:commons:+'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.5.4'
compile group: 'commons-cli', name: 'commons-cli', version: '1.3.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.40.10'
compile group: 'org.fxmisc.easybind', name: 'easybind', version: '1.0.3'
compile group: 'org.scream3r', name: 'jssc', version: '2.8.0'
compile group: 'com.sparetimelabs', name: 'purejavacomm', version: '0.0.28'
compile 'net.java.dev.jna:jna:4.2.1'
compile 'commons-io:commons-io:2.4'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'net.jodah:concurrentunit:0.4.2'
}
//Native launchers
//Windows
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.edu.sc.seis.gradle:launch4j:1.6.1'
}
}
apply plugin: 'edu.sc.seis.launch4j'
launch4j {
//outputDir = 'native/windows'
bundledJrePath = 'jre'
dontWrapJar = true
jar = 'bin/derby-pro.jar'
mainClassName = 'com.neonorb.derbypro.main.DerbyPro'
icon = '../../src/main/resources/com/neonorb/derbypro/assets/derby-pro-icon-favicon.ico'
outfile = 'DerbyPro.exe'
companyName = 'Neon Orb'
productName = 'Derby Pro'
}
//OS X
/*plugins {
id "edu.sc.seis.macAppBundle" version "2.1.0"
}
macAppBundle {
mainClassName = "com.example.myApp.Start"
icon = "myIcon.icns"
bundleJRE = true
javaProperties.put("apple.laf.useScreenMenuBar", "true")
backgroundImage = "doc/macbackground.png"
}*/
Here is the manifest directory.
And here is the manifest content.
Manifest-Version: 1.0
Implementation-Version: 0.0.0
Main-Class: com.neonorb.derbypro.main.DerbyPro
Demo: true

Your jar file contains duplicate entries which probably cause problems when being deployed. If you run the following command with your jar file you will see the duplicate entries:
$ unzip -l derby-pro-demo.jar |grep META
0 01-26-16 11:47 META-INF/
116 01-26-16 11:47 META-INF/MANIFEST.MF
321 06-09-15 18:42 META-INF/LICENSE
825 06-09-15 18:42 META-INF/NOTICE
...
11358 06-14-15 12:06 META-INF/LICENSE.txt
172 06-14-15 12:06 META-INF/NOTICE.txt
...
11358 04-03-15 14:30 META-INF/LICENSE.txt
301 04-03-15 14:30 META-INF/NOTICE.txt
The problem is caused by the fatJar. See here and here.
When creating a fat jar, the duplicate entries should be resolved. I have no experience with gradle. The issue (first link) is still marked "open", so I assume there may not be an easy fix. As a work around (if this is possible and works for you), I could imagine to copy all jar content first to a temporary directory. This would overwrite duplicate entries. Then you could build the fat jar from the temporary directory. However, I'd be very careful with that. First some duplicate class files may be relevant, and second the LICENSE, NOTICE, etc. files certainly will cause a license problem.

The JNLP file contains a main class attribute, Java Web Start is trying to create the manifest with that main class. Therefore removing the main class attribute from the JNLP file allows it to run.

Related

Hibernate error when trying to enable .ear file

I deployed the ear files to a new server and I'm getting this error when I try to enable the .ear file via the JBoss console. The server it is on is using Wildfly. We are using Java 8 and Gradle. I have a number of Google searches and looked at threads here, but I haven't found a link which gets me close enough to a solution. There is a corresponding EJB info I can add in if need be. MySQL servers are both 5.6.
Error: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Request
{
"address" => [("deployment" => "EnsScheduler.ear")],
"operation" => "deploy"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"EnsScheduler.ear/EnsSchedulerEJB.jar#EnsDs\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"EnsScheduler.ear/EnsSchedulerEJB.jar#EnsDs\": org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set"}},
"rolled-back" => true
}
Here's some of the configure files data.
Application.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:application="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>EnsScheduler</display-name>
<module>
<web>
<web-uri>EnsSchedulerWeb.war</web-uri>
<context-root>/</context-root>
</web>
</module>
<module>
<ejb>EnsSchedulerEJB.jar</ejb>
</module>
</application>
JBoss Deployment structure XML
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.google.guava" export="true" />
<module name="net.sourceforge.cssparser" export="true" />
<module name="org.w3c.css.sac" export="true" />
</dependencies>
</deployment>
</jboss-deployment-structure>
build.gradle
apply plugin: 'ear'
apply plugin: 'eclipse-wtp'
dependencies {
deploy project(':EnsSchedulerEJB')
deploy project(path:':EnsSchedulerWeb', configuration:'archives')
}
eclipse {
wtp {
facet {
facet name: 'jst.ear', version: '7.0'
}
}
project {
//buildCommands.clear()
//buildCommand 'org.eclipse.jdt.core.javabuilder'
natures 'org.eclipse.jdt.core.javanature'
}
classpath {
//file {
// whenMerged { classpath ->
// classpath.entries.removeAll { it.kind =='con' || it.kind == 'lib'}
// }
//}
containers 'org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/WildFly 8.x Runtime'
}
}
build.gradle for the EJB project.
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
configurations{
}
dependencies {
//java ee, jsf, jpa, and such
compile group: 'javax', name: 'javaee-api', version: '7.0'
compile 'javax.inject:javax.inject:1'
compile 'javax.enterprise:cdi-api:1.1'
compile 'javax.validation:validation-api:1.1.0.Final'
compile 'org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final'
compile 'org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_2.0_spec:1.0.0.Final'
//hibernate was search 4.5.0 and core 4.3.1, lucene 3.6.2
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
compile 'org.hibernate:hibernate-core:4.3.10.Final'
runtime 'org.hibernate:hibernate-core:4.3.10.Final'
runtime 'org.apache.lucene:lucene-core:4.10.4'
//mySql
compile 'mysql:mysql-connector-java:5.1.30'
runtime 'mysql:mysql-connector-java:5.1.30'
//testCompile group: 'junit', name: 'junit', version: '4.11'
}
eclipse {
wtp {
facet {
facets.clear()
facet type: org.gradle.plugins.ide.eclipse.model.Facet.FacetType.fixed, name: 'jst.ejb'
facet name: 'java', version: '1.8'
facet name: 'jst.ejb', version: '3.2'
facet name: 'jst.cdi', version: '1.1'
facet name: 'jpt.jpa', version: '2.1'
file{
whenMerged{ wtpFacet ->
def util = wtpFacet.facets.find{facet ->
facet.name == 'jst.utility' && facet.type == org.gradle.plugins.ide.eclipse.model.Facet.FacetType.installed}
wtpFacet.facets.remove(util)
println("facets: " + wtpFacet.facets)
}
withXml {xml ->
if ( ! xml.asNode().runtime ) {
NodeBuilder bld = new NodeBuilder()
xml.asNode().children().add(0, bld.runtime(name: 'WildFly 8.x Runtime'))
}
}
}
}
}
project {
buildCommands.clear()
buildCommand 'org.eclipse.jdt.core.javabuilder'
buildCommand 'org.eclipse.wst.common.project.facet.core.builder'
buildCommand 'org.hibernate.eclipse.console.hibernateBuilder'
buildCommand 'org.jboss.tools.cdi.core.cdibuilder'
buildCommand 'org.eclipse.wst.validation.validationbuilder'
natures 'org.eclipse.jem.workbench.JavaEMFNature',
'org.eclipse.wst.common.modulecore.ModuleCoreNature',
'org.hibernate.eclipse.console.hibernateNature',
'org.eclipse.jdt.core.javanature',
'org.eclipse.wst.common.project.facet.core.nature',
'org.jboss.tools.cdi.core.cdinature'
linkedResource name: 'lib/mysql-connector-java-5.1.30-bin.jar', type: '1', locationUri: 'PARENT-1-PROJECT_LOC/libraries/mysql-connector-java-5.1.30-bin.jar'
}
classpath{
minusConfigurations += [ configurations.compile ]
plusConfigurations += [ configurations.runtime ]
containers 'org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/WildFly 8.x Runtime'
}
}

error: package javafx.scene.media does not exist

I'm trying to create javafx media player as gradle project, but got this error.error: package javafx.scene.media does not exist on line: import javafx.scene.media.Media;
Here is my build.gradle
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
group 'life.antonov'
version '1.0'
mainClassName='life.antonov.muza.Main'
sourceCompatibility = 11
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.openjfx', name: 'javafx-controls', version: '13'
compile group: 'org.openjfx', name: 'javafx-fxml', version: '13 '
compile group: 'org.openjfx', name: 'javafx-media', version: '13'
}
I'm tried to unzip downloaded javafx-media jar file and it is almost empty:
$ unzip javafx-media-13.jar
Archive: javafx-media-13.jar
creating: META-INF/
inflating: META-INF/MANIFEST.MF
Why?
Maybe I wrote wrong dependencies?
What I have to do to make my application compile and work?
I have not tested it, but:
Replace:
modules = [ 'javafx.controls', 'javafx.fxml' ]
With
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.media' ]
If you want to use MediaView control in javafx you must to do 2 steps
Step1: add requires javafx.media;
module com.codegym.videoplayerfx {
requires javafx.controls;
requires javafx.fxml;
requires javafx.media; // You must add this line
opens com.codegym.videoplayerfx to javafx.fxml;
exports com.codegym.videoplayerfx;
}
Step2: Add dependency in pom.xml for maven (or build.gradle for gradle). After that you must press build. Try orther dependency version if does't work
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>16</version>
</dependency>

Spring Boot JAR not executing as an init.d service

I have created a Spring Boot application with the following build.gradle file (Gradle version 5.4.1):
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
bootJar {
launchScript()
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.1.6.RELEASE', ext: 'pom'
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.6.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '5.1.7.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
compile group: 'org.hibernate', name: 'hibernate-hikaricp', version: '5.3.10.Final'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
}
When I try creating a JAR using ./gradlew bootJar and running it using the following command sudo service project start, the following error message shows up:
Failed to restart project.service: Unit project.service not found.
I have added the symlink to the JAR file in /etc/init.d, still it displays the above error when starting. What am I missing here?
Try add :
springBoot {
executable = true
}
I am using maven with :
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
Check if jar file permission is set executable e.g. (755)
Try to start ./$YOURAPP.jar to test if your build was correct
first check if the project.service exists
sudo vim /etc/systemd/system/project.service
if it doesnt you may need to make one.
The contents of this file looks something like:
https://www.baeldung.com/spring-boot-app-as-a-service
dont forget to make the script executable with chmod +x
after you make the service you need to run the folowing comantds to get it to work:
sudo systemctl restart rsyslog
sudo systemctl enable project.service
sudo service project start
sudo service project status

IntelliJ can't find slf4j logger with gradle

I have a project for which I use gradle, and I wanted to use the logger slf4j provides.
Running in Android Studio produces the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.mypkg.Main.<clinit>(Main.java:9)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
My build.gradle for the project:
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.0'
}
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'application'
jar {
manifest {
attributes 'Main-Class': "Main"
}
}
shadowJar {
mergeServiceFiles('META-INF/spring.*')
}
mainClassName = 'com.mypkg.Main'
dependencies {
compile 'com.squareup:otto:1.3.5'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
compile 'com.squareup.okhttp:okhttp:2.7.4'
compile 'com.squareup.okhttp:okhttp-ws:2.7.4'
compile 'com.parse.bolts:bolts-android:1.2.1'
compile 'org.json:json:20140107'
compile 'org.bouncycastle:bcprov-jdk15on:1.52'
compile 'commons-codec:commons-codec:1.10'
compile 'org.scream3r:jssc:2.8.0'
compile 'ch.qos.logback:logback-classic:1.1.3'
compile 'ch.qos.logback:logback-core:1.1.3'
compile 'org.json:json:20140107'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
compile group: 'org.springframework.shell', name: 'spring-shell', version: '1.2.0.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '4.2.4.RELEASE'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
If I build this project with gradle, the shadow plugin generates a fat jar, which runs from the console nicely, it includes the logger, but from the IDE I'm having difficulties finding the LoggerFactory. I read here that I should add the logger to the classpath but since I don't explicitly include a jar, rather than marking it as a dependency, I'm not sure how this would be possible.
Please advise.
Cheers!
The classpath is out of sync, few options here
Refresh the project in IntelliJ (the older versions of IntelliJ are not ideal with gradle integration)
add apply plugin: 'idea' to your build.gradle and then run gradle idea to regenerate .iml .ipr .iws files in your project and pick up dependencies from gradle.(Not ideal! see why)
Download latest version of IntelliJ and redo option 1
Edit: Thanks #CrazyCoder for this hint.

use gradle to embed dependency information into manifest

I would like to embed dependency information into my manifest file, so that I can expose this information at runtime. i.e. I can see which version of a library is used by a particular running instance of my service.
I'm using gradle to build my 'fatjar':
shadowJar {
mergeServiceFiles()
archiveName "service.jar"
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
manifest {
attributes('Main-Class': "service.Service",
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Implementation-Version': version,
'Implementation-Title': project.name)
}
}
And I have dependencies on various other libraries:
dependencies {
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.39'
...
}
How can I add the dependency information into my manifest file? For example:
Manifest-Version: 1.0
Implementation-Title: service
Implementation-Version: Local Build
Built-By: me
Built-Date: Wed Jun 22 14:13:53 BST 2016
Built-JDK: 1.8.0_91
Main-Class: service.Service
Dependency-mysql-connector-java: mysql:mysql-connector-java:5.1.39
It can be done in the following way:
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:19.0'
compile 'com.google.inject:guice:4.1.0'
}
shadowJar {
mergeServiceFiles()
archiveName "service.jar"
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
manifest {
attributes(
[
'Main-Class': "service.Service",
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Implementation-Version': 'version',
'Implementation-Title': project.name,
] +
project.configurations.compile.allDependencies.collect { d ->
[
("dependency-${d.group.replaceAll('\\.','-')}".toString()):"$d.group:$d.name:$d.version"
]
}.sum()
)
}
}
The script above produces the following MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: service.Service
Built-By: opal
Built-Date: Mon Jul 04 17:27:05 CEST 2016
Built-JDK: 1.8.0_91
Implementation-Version: version
Implementation-Title: 37969253
dependency-com-google-guava: com.google.guava:guava:19.0
dependency-com-google-inject: com.google.inject:guice:4.1.0
Since attributes takes Map as an argument, you need to collect them dependencies, transform them to Map and sum the maps.

Categories

Resources