Jar Manifest changes getResource() path - maven

I have a critical problem after building a jar file via maven. I told the maven-jar-plugin to use several classpaths. The created jar contains the following manifest:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.8.0_25
Main-Class: EntryPoint
Class-Path: Launcher-1.0.jar lib/ Introduction-1.0.jar
But when I try to load a resource from a method in EntryPoint.class, the root path is /xx/xx/lib/ and I am not inside the jar file, it is the lib/ folder which was specified in the Manifest.
This is the snippet I use inside the method of EntryPoint:
System.out.println(EntryPoint.class.getResource("").getPath().toString());
BUT: I need to load an xml file inside the jar, how can I get back?

javax.swing.ImageIcon ICONE =new javax.swing.ImageIcon(getClass().getClassLoader().getResource("path/subdir/video.png"));
OR
Icon ic2=new ImageIcon(ThisCurentClassName.class.getResource("/fr/package/someresource/icones/server1.png"));

Related

how can I correctly upzip .jar and recombine it after making some change to MANIFEST.MF

I unzip a jar file using 7zip , here is the origin content of
/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: liuyang
Class-Path: . lib/commons-logging-1.1.1.jar lib/sqljdbc4-4.0.jar
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_171
Main-Class: org.tinyradius.test.TestServer
what I want to do is add one addtional Class-Path , the final content after I change is :
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: liuyang
Class-Path: . lib/commons-logging-1.1.1.jar lib/log4j-1.2.17.jar lib/sqljdbc4-4.0.jar
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_171
Main-Class: org.tinyradius.test.TestServer
you can see I only add lib/sqljdbc4-4.0.jar
now I goto window command line and type :
jar cfv tinyradius-0.9.9.jar META-INF org
and my folder looks like this :
after this command finish , it do appear a new jar file named: tinyradius-0.9.9.jar
but after I unzip this new jar file , I find new MANIFEST.MF have such content :
Manifest-Version: 1.0
Created-By: 1.8.0_171 (Oracle Corporation)
why it is so different with what I updated ?
Create a temporary folder on your desktop. Drop the jar into that folder. Rename the jar tinyradius-0.9.9.jar to tinyradius-0.9.9.zip and unzip it. Make the change to the manifest. Select all the files and compress them. Rename the zip back to jar.

Eclipse RCP Fragment How to Build library.jar

I have a plug-in fragment which contributes a jar file to the host plug-in, following these instructions. It works by creating a file library.jar which is specified in build.properties and associated with a directory which contains the source to be built.
It all works as expected, except I can't figure out how to cause library.jar to be created in Eclipse. When I run a Maven build that points to my fragment project and includes it as a module, the file library.jar shows up in the project directory. But building or cleaning the project in eclipse does not create the file.
I want other developers to be able to generate library.jar in their Eclipse workspace without running the Maven build. I'm really surprised that the Maven build creates libary.jar in the plug-in project itself, and not just in the product created in the build target. There should be a way to get Eclipse to do this without running the Maven build.
EDIT:
build.properties:
bin.includes = META-INF/,\
library.jar
source.library.jar = src/
MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Custom
Bundle-SymbolicName: org.python.pydev.custom
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.python.pydev;bundle-version="5.1.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Eclipse-PatchFragment: true
Bundle-ClassPath: library.jar,
.
Require-Bundle: org.python.pydev.debug;bundle-version="5.5.0",
org.eclipse.cdt.debug.core;bundle-version="8.0.0",
org.apache.log4j
Eclipse will build the library.jar rather than putting the class files in the normal place when the build.properties file looks like:
bin.includes = META-INF/,\
library.jar
source.library.jar = src/
The library.jar entry in the bin.includes replaces the normal . entry.
The source.library.jar entry says that the Java files in the src directly should be put in the library.jar.
The Bundle-Classpath entry in your MANIFEST.MF should be:
Bundle-ClassPath: library.jar
(so no '.' entry)

Changing default filesystem in WAR file prepared by Gradle plugin

I would like to deploy a mock service developed with SoapUI. I have SoapUI project, web.xml and now I would like to add them to WAR archive. I'm using Gradle to prepare this WAR file.
My code below:
war {
archiveName 'mock.war'
webXml file ('src/main/webapp/web.xml')
}
Default filesystem of produced archive is:
META-INF
WEB-INF
lib
some libs...
classes (this folder I would like to rename to 'soapui')
some files...
web.xml
Is there any possibility, to change the name of 'classes' folder?
Thanks in advance,
Patryk

WildFly - Adding JARs to classpath

I am using WildFly 8.2.1.
I need to add specific JAR files to the class path. How can I do that?
Do I need to get inside the module hell?
All I need is to add a couple of extra Oracle JAR files to enable using TLS on the data source connection...
When you build your .war file, add them to the /WEB-INF/lib directory. They will be accessible on the classpath from there. In eclipse the eclipse maven plugin, m2e, will do it by reading your POM file, or of course, maven run by hand will do it.
In the POM file, have it packaged as a war
<packaging>war</packaging>
and declare your jar as a dependency.

Not able to access classes in javamail in OSGi

I have an OSGi bundle and I'm using java mail api in it to add mail functionality.
The problem I'm facing is, the bundle class loader is not adding the entries for mail-1.4.jar and activation.jar in classpath variable which it creates while loading the local or global classes.
I've added the mail-1.4.jar and activation.jar in the bundle classpath in manifest and these jar are simple jars(not the OSGi bundles). And these are in lib directory in my bundle.
Now while loading javax.mail.Address class ClassNotFoundException is thrown.
And this is when I'm running my application using command line.
It works completely fine when I run it in Eclipse.
I'm using equinox as my container.
Any suggestions?
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Workexp
Bundle-SymbolicName: com.gslab.workexp
Bundle-Version: 1.0.0
Bundle-Activator: com.gslab.workexp.Activator
Bundle-Vendor: GSLAB
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework
Bundle-ClassPath: .,
lib/mysql-connector-java-5.1.20-bin.jar,
lib/commons-beanutils-1.8.0.jar,
lib/commons-collections-2.1.1.jar,
lib/commons-digester-2.1.jar,
lib/commons-javaflow-20060411.jar,
lib/commons-logging-1.1.1.jar,
lib/iText-2.1.7.jar,
lib/jasperreports-4.6.0.jar,
lib/jdt-compiler-3.1.1.jar,
lib/log4j-1.2.9.jar,
lib/mail-1.4.jar,
lib/activation.jar
Your use of the bundle classpath is unusual. You should use Import-Package (best practice) or Require-Bundle for dependencies. Bundle classpath is saying all those jars are packaged inside a lib folder inside your bundle archive. I suspect this isn't the case, and even if it was, you'd be totally bypassing all the modularity Eclipse gives you.
Try adding the 'javax.mail' package to your Import-Package header. For an explanation of why this isn't needed in Eclipse, see i/Why_does_Eclipse_find_javax.swing_but_not_Felix%3F.
Make sure you have included your lib folder inside the bin.includes (Build Tab in the Manifest editor) or they won't get exported in the final jar.
This is a very annoying 'bug' that it works in eclipse (because the files are accessible in the file system) but the builder will ignore not included files.

Resources