I'm trying to add proguard to obfuscate my java code with nebeans. I've followed a blog where it says that I must add some code in build.xml. I've modified build.xml but it gives me an error:
jar doesn't support the nested "property" element.
I added proguard location and all code of the blog but always gives me that error. Could you help me please? Thanks.
Blog is https://dzone.com/articles/obfuscating-netbeans-java-appl
I put the code of my build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AFB_CONEXIONES_DENTRO" default="default" basedir=".">
<description>Builds, tests, and runs the project AFB_CONEXIONES_DENTRO.</description>
<import file="nbproject/build-impl.xml"/>
<target name="-post-jar">
<jar jarfile="dist/AFB_con_librerias.jar">
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
<zipfileset src="lib/ojdbc6.jar" excludes="META-INF/*" />
<zipfileset src="lib/proguard.jar" excludes="META-INF/*" />
<zipfileset src="lib/log4j-1.2.17.jar" excludes="META-INF/*" />
<zipfileset src="lib/postgresql-9.2-1002.jdbc4.jar" excludes="META-INF/*" />
<property name="proguard.jar.path" value="/home/y9c4db/Downloads/proguard6.1.1/lib/proguard.jar" />
<taskdef resource="proguard/ant/task.properties"
classpath="${proguard.jar.path}" />
<echo message="Obfuscating ${dist.jar}..."/>
<mkdir dir="${build.dir}/obfuscated"/>
<proguard printmapping="${build.dir}/obfuscated/${application.title}.map"
renamesourcefileattribute="SourceFile" ignorewarnings="true">
<!-- Specify the input jars, output jars, and library jars. -->
<injar file="${dist.jar}" />
<outjar file="${build.dir}/obfuscated/BalloonWindCore_JavaSE.jar" />
<libraryjar path="${javac.classpath}" />
<libraryjar file="${java.home.path}/jre/lib/rt.jar" />
<!-- Keep some useful attributes. -->
<keepattribute name="InnerClasses" />
<keepattribute name="SourceFile" />
<keepattribute name="LineNumberTable" />
<keepattribute name="Deprecated" />
<keepattribute name="*Annotation*" />
<keepattribute name="Signature" />
<!-- Preserve all public classes, and their public and protected fields and methods. -->
<keep access="public">
<field access="public protected" />
<method access="public protected" />
</keep>
<!-- Preserve all .class method names. -->
<keepclassmembernames access="public">
<method type ="java.lang.Class"
name ="class$"
parameters="java.lang.String" />
<method type ="java.lang.Class"
name ="class$"
parameters="java.lang.String,boolean" />
</keepclassmembernames>
<!-- Preserve all native method names and the names of their classes. -->
<keepclasseswithmembernames>
<method access="native" />
</keepclasseswithmembernames>
<!-- Preserve the methods that are required in all enumeration classes. -->
<keepclassmembers extends="java.lang.Enum">
<method access="public static"
type="**[]"
name="values"
parameters="" />
<method access="public static"
type="**"
name="valueOf"
parameters="java.lang.String" />
</keepclassmembers>
<!-- Explicitly preserve all serialization members. The Serializable
interface is only a marker interface, so it wouldn't save them.
You can comment this out if your library doesn't use serialization.
With this code serializable classes will be backward compatible -->
<keepnames implements="java.io.Serializable"/>
<keepclassmembers implements="java.io.Serializable">
<field access ="final"
type ="long"
name ="serialVersionUID" />
<field access ="!static !transient"
name ="**"/>
<field access ="!private"
name ="**"/>
<method access ="!private"
name ="**"/>
<method access ="private"
type ="void"
name ="writeObject"
parameters="java.io.ObjectOutputStream" />
<method access ="private"
type ="void"
name ="readObject"
parameters="java.io.ObjectOutputStream" />
<method type ="java.lang.Object"
name ="writeReplace"
parameters="" />
<method type ="java.lang.Object"
name ="readResolve"
parameters="" />
</keepclassmembers>
<!-- Your application may contain more items that need to be preserved;
typically classes that are dynamically created using Class.forName -->
</proguard>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
</target>
</project>
Please any help? Thanks
Related
I have this Runtime Exception. I'm using IntelliJ IDEA.
I've downloaded apache commons dbcp2 from apache's site.
So far so good, but now, I add that module by File > Project Structure.
Module addition
As you can see I've done that same steps for MySQL Library, and its fine, all works; In fact, when I'm typing functions that appear in that apache common package doesnt appears any error. For example BasicDataStructure
public static DataSource getDataSource(){
BasicDataSource ds = new BasicDataSource();
ds.setUrl(JDBC_URL);
ds.setUsername(JDBC_USER);
ds.setPassword(JDBC_PASS);
ds.setInitialSize(3);
return ds;
}
But at time to run it:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/pool2/SwallowedExceptionListener
at datos.Conexion.getDataSource(Conexion.java:19)
at datos.Conexion.getConnection(Conexion.java:33)
at test.ManejoPersonas.main(ManejoPersonas.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.SwallowedExceptionListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
This is my .iml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$USER_HOME$/Documents/JAVA Libraries/mysql-connector-java-8.0.19/mysql-connector-java-8.0.19/mysql-connector-java-8.0.19.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$USER_HOME$/Documents/JAVA Libraries/commons-dbcp2-2.7.0-bin/commons-dbcp2-2.7.0/commons-dbcp2-2.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
And I dont know why, because while I'm coding there arent any problem.
Thanks a lot.
It looks like you also need Apache Commons Pool dependency in the project which is missing.
I'm trying to create a relation between Product2Componen
<relation code="Product2Components" localized="false" autocreate="true">
<deployment table="ProdsCompRels" typecode="30008" />
<sourceElement qualifier="product" type="Product" cardinality="one" collectiontype="list">
<modifiers read="true" write="true" search="true" optional="true" />
</sourceElement>
<targetElement qualifier="components" type="SimpleCMSComponent" cardinality="many">
<modifiers read="true" write="true" search="true" optional="true" />
</targetElement>
</relation>
However , hybris OOTB has already a relation within product2ProductDetailComponent:
<relation code="ProductDetailComponentsForProduct" generate="true" localized="false" autocreate="true">
<sourceElement qualifier="productDetailComponents" type="ProductDetailComponent" cardinality="many" collectiontype="list">
<modifiers read="true" write="true" search="true" optional="true" />
</sourceElement>
<targetElement qualifier="product" type="Product" cardinality="one">
<modifiers read="true" write="true" search="true" optional="true" />
</targetElement>
</relation>
And when I compile it returns me this error because of this already existing relation that is completly useless to me:
Attribute CmsLinkComponent.product(Product):((cms2))::YAttributeDescriptor[cms2-items.xml:190(RelationTypeTagListener)][JALO] duplicates inherited attribute SimpleCMSComponent.product(Product):((puigcore))::YAttributeDescriptor[puigcore-items.xml:488(RelationTypeTagListener)][JALO]. Remove it or specify it as redeclared
How can I redeclare a relation ? Or what should I do here ?
Since the OOTB ProductDetailComponent extends SimpleCMSComponent and you want to use SimpleCMSComponent so I think you can simply use OOTB relation.
But if you really want to decare your own attribute/relation then you have to provide a different qualifier other than "product", as the product qualifier is already been used in the OOTB relation ProductDetailComponentsForProduct, where ProductDetailComponent is the subtype of SimpleCMSComponent.
<relation code="Product2Components" localized="false" autocreate="true">
<deployment table="ProdsCompRels" typecode="30008" />
<sourceElement qualifier="productRef" type="Product" cardinality="one" collectiontype="list">
<modifiers read="true" write="true" search="true" optional="true" />
</sourceElement>
<targetElement qualifier="components" type="SimpleCMSComponent" cardinality="many">
<modifiers read="true" write="true" search="true" optional="true" />
</targetElement>
</relation>
I am trying to obfuscate an enumerated type file in java and I've noticed that I can get proguard to obfuscate the names of the enumerated types like I want, including the references, however it keeps the old names of the enumerated types in the class file.
For example:
Proguard Configuration:
<project name="Library" default="obfuscate" basedir=".">
<taskdef resource="proguard/ant/task.properties" classpath="proguard.jar"/>
<target name="build">
<javac srcdir="src" includeantruntime="true" destdir="build">
<compilerarg value="-Xlint:deprecation" />
</javac>
<jar jarfile="jarfile.jar" basedir="build" />
</target>
<target name="obfuscate">
<taskdef resource="proguard/ant/task.properties"
classpath="lib/proguard.jar" />
<proguard printmapping="out.map"
allowaccessmodification="true"
obfuscationdictionary="random.txt"
classobfuscationdictionary="random-c.txt"
packageobfuscationdictionary="random-p.txt"
renamesourcefileattribute="SourceFile">
<!-- Specify the input jars, output jars, and library jars. -->
<injar file="jarfile.jar" />
<outjar file="output/library_out.jar" />
<libraryjar file="${java.home}/lib/rt.jar" />
<!-- Keep some useful attributes. -->
<keepattribute name="InnerClasses" />
<keepattribute name="SourceFile" />
<keepattribute name="LineNumberTable" />
<keepattribute name="Deprecated" />
<keepattribute name="*Annotation*" />
<keep name="test.**" allowobfuscation="true">
<field access="public protected" />
<method access="public protected" />
</keep>
<keepclassmembernames access="public">
<method access = "public static"
type = "void"
name = "main"
parameters = "java.lang.String[]"/>
</keepclassmembernames>
<keepclassmembernames access="public">
<method type ="java.lang.Class"
name ="class$"
parameters="java.lang.String" />
<method type ="java.lang.Class"
name ="class$"
parameters="java.lang.String,boolean" />
</keepclassmembernames>
<!-- Preserve all native method names and the names of their classes. -->
<keepclasseswithmembernames includedescriptorclasses="true">
<method access="native" />
</keepclasseswithmembernames>
<!-- Preserve the methods that are required in all enumeration classes. -->
<keepclassmembers allowoptimization="true" type="enum">
<method access="public static"
type="**[]"
name="values"
parameters="" />
<method access="public static"
type="**"
name="valueOf"
parameters="java.lang.String" />
</keepclassmembers>
<!-- Explicitly preserve all serialization members. The Serializable
interface is only a marker interface, so it wouldn't save them.
You can comment this out if your library doesn't use serialization.
If your code contains serializable classes that have to be backward
compatible, please refer to the manual. -->
<keepclassmembers implements="java.io.Serializable">
<field access ="final"
type ="long"
name ="serialVersionUID" />
<field access ="static final"
type ="java.io.ObjectStreamField[]"
name ="serialPersistentFields" />
<method access ="private"
type ="void"
name ="writeObject"
parameters="java.io.ObjectOutputStream" />
<method access ="private"
type ="void"
name ="readObject"
parameters="java.io.ObjectInputStream" />
<method type ="java.lang.Object"
name ="writeReplace"
parameters="" />
<method type ="java.lang.Object"
name ="readResolve"
parameters="" />
</keepclassmembers>
<!-- Your application may contain more items that need to be preserved;
typically classes that are dynamically created using Class.forName -->
</proguard>
</target>
</project>
Two Java Files:
mainClass.java:
package test;
public class mainClass {
public static void main(String[] args){
System.out.println(TestEnum.TEST);
System.out.println(TestEnum.TESTAGAIN);
System.out.println(TestEnum.TESTAGAINAGAIN);
}
}
TestEnum.java:
package test;
public enum TestEnum {
TEST,
TESTAGAIN,
TESTAGAINAGAIN;
}
"obfuscated" class file of TestEnum.java contains the following Strings:
> $ strings ff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44.class
()Ljava/lang/Object;
R()[Lff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44;
5(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
c(Ljava/lang/String;)Lff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44;
(Ljava/lang/String;I)V
<clinit>
<init>
Code
OLff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44;
TEST
TESTAGAIN
TESTAGAINAGAIN
P[Lff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44;
(bd5e3e98f5d9552fad4cea7dd9f09ec970b5c537
c4b09ad3a6fc8bdb613d7a47ae6b62
clone
$f0330a7bb6fff9a6c846ffe92c696633cc9c
'fca7ea2fd7d090d4fc3b0f2f22c2a234b16cebb
Mff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44
java/lang/Enum
valueOf
values#1
Here is the string dump of the mainClass:
> $ strings ff42d24eb40678f60462c47c07218c6ba0be/e254fec352c913191237dc8c2e9030b20da756f2.class
(Ljava/lang/Object;)V
([Ljava/lang/String;)V
<init>
Code
OLff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44;
Ljava/io/PrintStream;
(bd5e3e98f5d9552fad4cea7dd9f09ec970b5c537
$f0330a7bb6fff9a6c846ffe92c696633cc9c
'fca7ea2fd7d090d4fc3b0f2f22c2a234b16cebb
Mff42d24eb40678f60462c47c07218c6ba0be/e254fec352c913191237dc8c2e9030b20da756f2
Mff42d24eb40678f60462c47c07218c6ba0be/fdbdd99cf9e2f8336f5ac70ee1c6b0c002e23d44
java/io/PrintStream
java/lang/Object
java/lang/System
main
println
As you can see TEST, TESTAGAIN, and TESTAGAINAGAIN are still contained within the class file but are not actually used in mainClass, instead their obfuscated name is used.
In fact, if you look at these class files in a program like JD-GUI, they don't show up either, but they are contained within the class file themselves. Is there some way to remove the TEST, TESTAGAIN, and TESTAGAINAGAIN within the class file via proguard?
This was run with proguard 5.3.3, compiling with java 8. An example of this can be found here: https://github.com/mirabellatook/ant-proguard-example
This is part of my jboss-esb.xml file:
<action name="HotelAvailRq_To_HotelAvailRequest" class="org.jboss.soa.esb.smooks.SmooksAction">
<property name="smooksConfig"
value="requestConverters/HotelAvailRq_To_HotelAvailRequest.xml" />
<property name="resultType"
value="JAVA" />
<!-- <property name="javaResultBeanId" value="hotel" /> -->
<!-- <property name="set-payload-location" value="map" /> -->
<property name="mappedContextObjects"
value="hotel,dateRange" />
<property name="reportPath"
value="C:\Documents and Settings\barrowj\esb-workspace\esb\smooks-in-report.html" />
</action>
<action name="print-result" class="org.jboss.soa.esb.actions.SystemPrintln" >
<property name="message" value="Read" />
<property name="printfull" value="true" />
</action>
<action name="availabilityCall"
class="org.jboss.soa.esb.actions.EJBProcessor">
<property name="ejb3" value="true" />
<property name="jndi-name" value="HotelBooking/remote" />
<property name="initial-context-factory"
value="org.jnp.interfaces.NamingContextFactory" />
<property name="provider-url" value="jnp://localhost:1099" />
<property name="method" value="availability" />
<property name="ejb-params">
<arg0 type="model.domain.Hotel">map.hotel</arg0>
<arg1 type="model.domain.value_objects.DateRange">body.map.dateRange</arg1>
<arg2 type="model.domain.value_objects.RoomRequest">roomRequest</arg2>
<arg3 type="model.domain.RatePlanList">ratePlanList</arg3>
<arg4 type="model.domain.AmenityList">amenityList</arg4>
<arg5 type="model.domain.types.Money">minimumRate</arg5>
<arg6 type="model.domain.types.Money">maximumRate</arg6>
<arg7 type="model.domain.Partner">partner</arg7>
</property>
</action>
The smooks call returns
body: [ objects:
{org.jboss.soa.esb.message.defaultEntry=
{ dateRange=DateRange [ thru=2010-03-24, from=2010-03-23],
roomRequest=RoomRequest [list=[GuestInfo [count=1, age=null]], numberOfRooms=1],
PTIME=null,
guestInfo=GuestInfo [count=1, age=null],
PUUID=null,
partner=Partner [partnerId=bukuser],
hotel=Hotel [id=61044, name=null, chainCode=BW, roomTypes=[], maxStay=P30D, bookings=[], ratePlans=[]],
guestInfoList=[GuestInfo [count=1, age=null]]},
SmooksExecutionContext={}} ]
So, I need to map the dateRange, roomRequest, guestInfo and the other EJB params to the EJB call. Is there a way to do this?
The documentation indicates you can, but doesn't say how to get a map value out of the context map in XML.
So the problem turns out to be the interaction between the smooks action and the ejb action. Smooks returns a hashmap of stuff. It puts that hashmap inside the message.body of the ESB. Which, in turn is a hashmap.
The ejb action is looking for message.getBody().get("name"), when it should be looking for message.getBody().get("smooksResults").get("name"). There is no way to tell the ejb action to look in there.
The only solution is to change the EJB action so it can look in the smooks results hashmap.
I was creating custom content model
in datalistModel.xml
<type name="dl:car">
<title>Car List</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:carName">
<title>Car Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:carCompany">
<title>Company Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
</type>
in share-datalist-form-config.xml
<!-- dl:contact type create car form -->
<config evaluator="model-type" condition="dl:car">
<forms>
<!-- Create item form -->
<form>
<field-visibility>
<!-- dl:contact type -->
<show id="dl:carName" />
<show id="dl:carCompany" />
</field-visibility>
<create-form template="../data-lists/forms/dataitem.ftl" />
</form>
</forms>
</config>
When I create a new car content in repository browser(I later configured menu to add content type 'Car'), the file name is 91b65385-86c6-4923-859d-6ecb3326319c.
<create-content>
<content id="plain-text" mimetype="text/plain" label="create-content.text" itemid="cm:content" icon="text"/>
<content id="html" mimetype="text/html" label="create-content.html" itemid="cm:content"/>
<content id="xml" mimetype="text/xml" label="create-content.xml" itemid="cm:content"/>
<content id="car" mimetype="text/xml" icon="xml" label="create-content.car" itemid="dl:car"/>
</create-content>
How can I make the file name to carName instead of 91b65385-86c6-4923-859d-6ecb3326319c
Any kind help is appreciated.
Take a look at the default 'share-datalist-form-config.xml'
You will see that almost every type specify <show id="cm:title" />
You could also just put <show id="name" /> or <show id="cm:name" /> to show the name attribute.
In order to put the title you will need to put the cm:titled aspect in your model.
Just check the 'datalistModel.xml' how the defaults are defined
And check this blog post to know a bit more how to create custom datalists.