Java(JavaFX): Maven Proguard doesnt obfuscate FX Ids - java

I am using the Proguard plugin to obfuscate my project which is using JavaFX.
The problem is, that the Ids in the .fxml files arent obfuscated, so its not possible to connect to the controller.
Already tried on google, without sucess...
Any ideas?
Proguard configuration:
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.11</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-final.jar</outjar>
<includeDependency>true</includeDependency>
<options>
<option>-keep public class com.skriptide.main.Main { public static void
main(java.lang.String[]); }
</option>
<option>-keepattributes Signature,*Annotation*,Exceptions</option>
<option>-dontusemixedcaseclassnames</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-verbose</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
<lib>${java.home}/lib/ext/jfxrt.jar</lib>
<lib>${java.home}/lib/jfxswt.jar</lib>
</libs>
<assembly>
<inclusions>
<inclusion>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>org.fxmisc.richtext</groupId>
<artifactId>richtextfx</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<library>true</library>
</inclusion>
</inclusions>
</assembly>
<archive>
<manifest>
<mainClass>com.skriptide.main.Main</mainClass>
</manifest>
</archive>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.2.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Thanks

You have to instruct ProGuard also to rename obfuscated classnames in the .fxml files. Assuming that they are already contained in the original jar file, you can try to add the following option to your proguard configuration:
<options>
...
<option>-adaptresourcefilecontents **.fxml</option>
...
</options>

Related

Lombok and AspectJ

I'm trying to use Lombok in combination with AspectJ and Maven.
So, what's the problem?
When I use the AspectJ Maven Plugin (www.mojohaus.org/aspectj-maven-plugin/), it takes the sources and compiles them and ignores changes made by Lombok. I followed this tutorial and came up with this code and AspectJ works, but Lombok dies with this message:
[WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: sun/apple javac 1.6, ECJ
So, does anyone know how to get Lombok in combination with AspectJ working?
Use ajc to process classes.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<complianceLevel>8</complianceLevel>
<source>8</source>
<target>8</target>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>
<!-- IMPORTANT-->
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<forceAjcCompile>true</forceAjcCompile>
<sources/>
<!-- IMPORTANT-->
<aspectLibraries>
<aspectLibrary>
<groupId>you.own.aspect.libary</groupId>
<artifactId>your-library</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>process-classes</phase>
<goals>
<!-- use this goal to weave all your main classes -->
<goal>compile</goal>
</goals>
<configuration>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>process-test-classes</phase>
<goals>
<!-- use this goal to weave all your test classes -->
<goal>test-compile</goal>
</goals>
<configuration>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/test-classes</weaveDirectory>
</weaveDirectories>
</configuration>
</execution>
</executions>
</plugin>
Use delombok to generate normal source code. And then proceed as you would if Lombok were not being used.
Store your Lombok-annotated code in main/src/lombok (for example) and then have the delombok plugin convert these annotations into normal code and into the directory /delomboked (for example).
I tried various solutions, finally specifying the javac compiler option like the below one worked
This works for me with command line mvn clean install, but in Eclipse IDE, the problem is not solved, eg. log is not correctly recognized for #Slf4j.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.10</version>
<configuration>
<verbose>true</verbose>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source>
<target>1.7</target>
<complianceLevel>1.7</complianceLevel>
<!-- <encoding>UTF-8</encoding> -->
<verbose>false</verbose>
<Xlint>ignore</Xlint>
<outxml>true</outxml>
<forceAjcCompile>true</forceAjcCompile>
<reweavable>false</reweavable>
<aspectLibraries>
<aspectLibrary>
<groupId>com.aspectj.library.yours</groupId>
<artifactId>your-library</artifactId>
</aspectLibrary>
</aspectLibraries>
<!-- this is important: start-->
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<!-- this is important: end-->
</configuration>
<executions>
<execution>
<!-- The right phase is very important! Compile and weave aspects after all classes compiled by javac -->
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies>
</plugin>
I had a configuration/excludes/exclude section with the spring-boot-maven-plugin where the "aspectjweaver" dependency had been declared. The exclude section had "org.projectlombok" in it, and looks like that's why none of my lombok annotations were being processed while building using "mvn clean install"
I initially had this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<excludes> <!------- THIS IS WHERE my problem started by exluding lombok -->
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
When I removed the excludes part, then the build started taking the lombok annotations and worked. This is my section now:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
SpringBoot AND Java: 16
At this moment (19-11-2022) aspectJ plugin not support 17
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/>
</parent>
...
YOUR GROUP, ARTIFACT NAME, VERSION ETC HERE
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>kkl.lib.dev.tools</groupId>
<artifactId>lib-dev-tools</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<showWeaveInfo/>
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<forceAjcCompile>true</forceAjcCompile>
<source>16</source>
<target>16</target>
<proc>none</proc>
<complianceLevel>16</complianceLevel>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
After reseach and testing all day, here is my success build.
Main idea is using javac to compile code first (compliance with lombok) and after that use aspectj only for weaving class.
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>unwovenClassesFolder</id>
<phase>generate-resources</phase>
<configuration>
<tasks>
<delete dir="${project.build.directory}/unwoven-classes"/>
<mkdir dir="${project.build.directory}/unwoven-classes"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<!-- Modifying output directory of default compile because non-weaved classes must be stored
in separate folder to not confuse ajc by reweaving already woven classes (which leads to
to ajc error message like "bad weaverState.Kind: -115") -->
<id>default-compile</id>
<configuration>
<source>16</source>
<target>16</target>
<outputDirectory>${project.build.directory}/unwoven-classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/unwoven-classes</weaveDirectory>
</weaveDirectories>
<!-- IMPORTANT-->
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<forceAjcCompile>true</forceAjcCompile>
<sources/>
<!-- IMPORTANT-->
<complianceLevel>16</complianceLevel>
<source>16</source>
<target>16</target>
</configuration>
<executions>
<execution>
<!-- Compile and weave aspects after all classes compiled by javac -->
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<complianceLevel>16</complianceLevel>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

How to make JAXB to annotate and provide equlas/hash code implementation

I am trying to use JAXB to generate classes from WSDL which are annotated with Jsr303Annotations and provide implementation of equals and hashcode.
Both of these work separately, however when i try to achieve both requirements then i get error:
An internal error occurred during: "Building workspace".
com.sun.tools.xjc.Plugin: Provider org.jvnet.jaxb2_commons.plugin.fixjaxb1058.FixJAXB1058Plugin could not be instantiated: java.lang.NoClassDefFoundError: org/jvnet/jaxb2_commons/reflection/util/Accessor
Could somebody tell me how to configure JAXB to do both of these ?
Bellow is my attempt to do so:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<id>generate-wsdl</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
<!-- <include>*.xsd</include> -->
</schemaIncludes>
<!-- <forceRegenerate>true</forceRegenerate> -->
<!-- <removeOldOutput>true</removeOldOutput> -->
<!-- <cleanPackageDirectories>true</cleanPackageDirectories> -->
<strict>true</strict>
<extension>true</extension>
<args>
<arg>-XJsr303Annotations</arg>
<arg>-Xannotate</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.3</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.4</version>
</plugin>
<plugin>
<groupId>com.github.krasa</groupId>
<artifactId>krasa-jaxb-tools</artifactId>
<version>1.1</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
Edit: Relevant dependencies i have tried to use:
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.9.4</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.jvnet.jaxb2_commons</groupId> -->
<!-- <artifactId>jaxb2-basics-annotate</artifactId> -->
<!-- <version>1.0.0</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.jvnet.jaxb2_commons</groupId> -->
<!-- <artifactId>jaxb2-commons-lang</artifactId> -->
<!-- <version>2.3</version> -->
<!-- </dependency> -->
Only the combination of first dependency and plugin for equals/hash code yield result.
If i include the other 2 dependencies then i get missing artifact -id message for every dependency in project.
Plugins for annotations work without explicit dependencies, when used without equals/hashcode plugin and vice versa.
Edit: Final solution in case anyone gets stuck on same issue
So it was required to separate annotations and equals/hash code plugins into separate executions, this resolved all issues.
Found a solution. This plugin requires another one dependency:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>com.argonio.fias.entity</generatePackage>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<readOnly>true</readOnly>
<removeOldOutput>true</removeOldOutput>
<verbose>true</verbose>
<extension>true</extension>
<args>
<arg>-no-header</arg>
<arg>-Xxew</arg>
<arg>-Xxew:instantiate lazy</arg>
<arg>-Xxew:plural</arg>
<arg>-Xequals</arg>
</args>
<plugins>
<plugin>
<groupId>com.github.jaxb-xew-plugin</groupId>
<artifactId>jaxb-xew-plugin</artifactId>
<version>1.5</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.4</version>
</plugin>
</plugins>
</configuration>
<dependencies>
<!-- This dependency is required to execute the plugin -->
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-tools</artifactId>
<version>0.9.4</version>
</dependency>
</dependencies>
</plugin>
Try to add this dependency. By the way, your version 0.6.3 seems low.
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-commons-lang</artifactId>
<version>2.3</version>
</dependency>
The answer of #Viacheslav is correct. Note however that you also need to add a dependency for the project:
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.9.4</version> <!-- same as jaxb2-basics plugin version -->
</dependency>
See http://confluence.highsource.org/display/J2B/JAXB2+Basics+Plugins for all details.

NoSuchElementException while launching an OSGI framework [duplicate]

I am trying to programatically start an OSGi framework (preferably Equinox) from Java and then load up any bundles.
So I was going through this article which says how to do that. But I am getting java.util.NoSuchElementException everytime at the below line everytime
ServiceLoader.load(FrameworkFactory.class).iterator().next();
Below is the code-
import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.logging.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public App() {
try {
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
//TODO: add some config properties
Framework framework = frameworkFactory.newFramework(config);
framework.start();
//... some other code
}
}
I am not sure what wrong I am doing here? I am having a maven based project. Below is my pom.xml file for this project-
<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">
<parent>
<groupId>com.host.Stream</groupId>
<artifactId>Stream-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../Build/superpom</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.host.domain.eye</groupId>
<artifactId>eye</artifactId>
<packaging>jar</packaging>
<name>eye</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration> <!-- Configuration of the archiver -->
<archive> <!-- Manifest specific configuration -->
<manifest> <!-- Classpath is added to the manifest of the created jar file. -->
<addClasspath>true</addClasspath> <!-- Configures the classpath prefix. This configuration option is used to
specify that all needed libraries are found under lib/ directory. -->
<classpathPrefix>lib/</classpathPrefix> <!-- Specifies the main class of the application -->
<mainClass>com.host.personalization.eye.App</mainClass>
</manifest>
</archive>
<includes>
<include>**/*.xml</include>
<include>**/*.class</include>
</includes>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>target/config/StreamConf</outputDirectory>
<resources>
<resource>
<directory>buildsrc/StreamConf</directory>
<includes>
<include>**</include>
</includes>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>target/config/StreamConf/eyewiring.xml</file>
<regex>false</regex>
<replacements>
<replacement>
<token>dynamic_build_label_place_holder</token>
<value>${project.artifactId}-${project.version}-${buildNumber}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<id>assembly</id>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<finalName>${project.artifactId}-${project.version}-${buildNumber}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>generate-resources</id>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<manifestLocation>buildsrc/StreamConf/META-INF</manifestLocation>
<instructions>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-SymbolicName>com.host.domain.eye</Bundle-SymbolicName>
<Import-Package>*,
pics,
links,
javax.el;version="[2.0,3.0)";resolution:=optional,
javax.inject;version="[1.0.0,2.0.0)",
javax.servlet;version="[2.5,4.0)",
javax.servlet.annotation;version="[3.0.0,4.0.0)",
javax.servlet.http;version="[2.5,4.0)",
javax.servlet.jsp;version="[2.0,3.0)",
javax.servlet.jsp.el;version="[2.0,3.0)",
org.aopalliance.aop;version="[1.0.0,2.0.0)",
org.eclipse.virgo.web.dm;version="[2.1.0.RELEASE,3.0)",
org.springframework.aop;version="[3.0.5.RELEASE,4.0)",
org.springframework.aop.framework;version="[3.0.5.RELEASE,4.0)",
org.springframework.aop.scope;version="[3.0.5.RELEASE,4.0)",
org.springframework.beans;version="3.0.5.RELEASE",
org.springframework.beans.annotation;version="[3.0.5.RELEASE,4.0)",
org.springframework.beans.factory;version="[3.0.5.RELEASE,4.0)",
org.springframework.beans.factory.annotation;version="[3.0.5.RELEASE,4.0)",
org.springframework.beans.factory.config;version="[3.0.5.RELEASE,4.0)",
org.springframework.context;version="[3.0.5.RELEASE,4.0)",
org.springframework.context.annotation;version="[3.0.5.RELEASE,4.0)",
org.springframework.context.config;version="[3.0.5.RELEASE,4.0)",
org.springframework.stereotype;version="[3.0.5.RELEASE,4.0)",
org.springframework.util;version="[3.0.5.RELEASE,4.0)",
org.springframework.web.bind.annotation;version="[3.0.5.RELEASE,4.0)",
org.springframework.web.context;version="[3.0.5.RELEASE,4.0)",
org.springframework.web.context.request;version="[3.0.5.RELEASE,4.0)",
org.springframework.web.context.support;version="[3.0.5.RELEASE,4.0)",
org.springframework.web.servlet;version="[3.0.5.RELEASE,4.0)",
org.springframework.web.servlet.config;version="[3.0.5.RELEASE,4.0)",
org.springframework.web.servlet.view;version="[3.0.5.RELEASE,4.0)",</Import-Package>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.host.Stream</groupId>
<artifactId>Streamframework</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.host.external</groupId>
<artifactId>ucirrus-db</artifactId>
<version>0.7.3</version>
</dependency>
<dependency>
<groupId>com.host.Stream</groupId>
<artifactId>Streamcore</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-extender</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-io</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
</project>
Service Loader searches the classpath for the interface you have asked for -- in this case FrameworkFactory. To fix it you need to put an OSGi Framework implementation on the classpath.
For example if you choose Felix, make sure that org.apache.felix.framework-<version>.jar is present on the classpath when you launch your application.
Make sure that your import for FrameworkFactory.class is on org.osgi.framework.launch.FrameworkFactory (not org.apache.felix.framework.FrameworkFactory). I ran into this same error (NoSuchElementException), when I broke up the statements the ServiceLoader.load() call was throwing a ClassNotFoundexception. Not sure why the load exception was eclipsed by the next call - but I reverted and confirmed this was happening. Good Luck!

Maven, Proguard and a jar I don't want

I'm obsfucating a project with the proguard-maven-plugin. Everything works fine except one thing: I don't want the original jar, neither in the target directory nor deployed in the repository. At the moment, I get the orignal jar and the obsfucated jar. Leaving it this way would cause problems within our buildserver as both artifacts would be deployed resulting in duplicate interfaces in the classpath. Using a blacklist on the buildserver is not an option.
Any idea?
Thank you!
If anybody has this issue, following configuration has worked for me. This renames the original jar to {final name}_proguard_base.jar and overrides the project jar with processed jar.
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>${proguard.version}</proguardVersion>
<obfuscate>false</obfuscate>
<injarNotExistsSkip>true</injarNotExistsSkip>
<injar>${project.build.finalName}.jar</injar>
<outputDirectory>${project.build.directory}</outputDirectory>
<addMavenDescriptor>true</addMavenDescriptor>
<attach>false</attach>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
<proguardInclude>${project.basedir}/proguard.conf</proguardInclude>
<options>
<option>-printseeds ${project.build.directory}/proguard-seeds.txt</option>
<option>-printusage ${project.build.directory}/proguard-shrinkusage.txt</option>
<option>-printmapping ${project.build.directory}/proguard-mapping.txt</option>
<option>-printconfiguration ${project.build.directory}/proguard-config.txt</option>
<option>-dontobfuscate</option>
<option>-keepdirectories</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
</options>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>${proguard.version}</version>
</dependency>
</dependencies>
</plugin>
You just need to specify the injar and outjar parameter pointed to the same jar, proguard will override the original jar.
My proguard setting (this setting for java 6, for java 7, change the groupid, artifactid and version accordingly):
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<includeDependency>false</includeDependency>
<injar>classes</injar>
<maxMemory>512m</maxMemory>
<libs>
<!-- dependency jar here -->
</libs>
<options>
<option>-keepattributes *Annotation*</option>
<option>-allowaccessmodification</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
<option>-dontusemixedcaseclassnames</option>
<option>-dontshrink </option>
</options>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard</artifactId>
<version>4.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
HTH.
According to documentation for the Proguard Plugin in Maven if you don't specify an outjar parameter it will override the input jar.
http://pyx4me.com/pyx4me-maven-plugins/proguard-maven-plugin/proguard-mojo.html
Setting the configuration option attach to true seems to replace the original project artifact.
http://pyx4me.com/pyx4me-maven-plugins/proguard-maven-plugin/proguard-mojo.html#attach

How to retrieve information from antrun back to maven?

How can I get information from maven-antrun-plugin back to Maven script? For example:
[...]
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec ... resultproperty="foo">
</target>
</configuration>
</execution>
</executions>
</build>
[...]
I'm interested to use this foo property later in Maven. How to it get out of antrun?
I am not sure if this solution will work, but maybe you can give it a try:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec ... resultproperty="foo">
<taskdef name="script"
classname="org.apache.tools.ant.taskdefs.optional.Script"
classpathref="maven.plugin.classpath" />
<script language="javascript">
<![CDATA[
project.setProperty("foo.mvn", ${foo});
]]>
</script>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<!-- Needed to run script (of Javascript) task. -->
<dependency>
<groupId>ant</groupId>
<artifactId>ant-optional</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>bsf</groupId>
<artifactId>bsf</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.6R5</version>
</dependency>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
The idea is to use define a property available for Maven (called here foo.mvn) by using the project.setProperty("foo.mvn", ${foo});. I am using JavaScript here, so you need to add some dependencies in the antrun plugin to be able to run it...

Categories