I am using Intellij IDEA to develop java desktop application. And I want to obfuscate my source code using proguard. How to integrate/use proguard on Intellij IDEA 2016.1.14?
1. add plugin Intellijguar2
2. in Project Structure ->modules->obfuscation press download yguard as it prompts. It brings to a html page where yguard is placed next to right edge of the page. Unzip.Get jar. Navigate to the jar. Set its path. Uncheck pedantic error-checking (optionally) , define project's MainClass. Ok it.
3. Build -> Build project -> build artifacts and get ordinary executable jar.
(If you cannot see artifacts enabled in Run menu go to file-> project structure ->artfact and create by + new item with dependensy to the main class)
4. build -> obfuscate *** module
5. Add YourProject/out/production/YourProject/firstfolder_of_packagename containing your project's *.class files(mine was 'uz', e.g.) .
6. Remove Module compile output Assign a path to the jar to be obfuscated below and press 'build'
7. Open obfuscated jar with zip program. Make sure the class files are all obfuscated by JD-GUI app.
8. cut off META-INF folder and add META-INF one from executable inobfuscated jar and also folders like libs or assets(or find out them in artifacts you setup previously) manually.
In turn you'll get an obfuscated executable jar
E.g. for json lib finally I've got the result view in zip editor:
I have not tried this (i like to find the easy way first) but, it should work if you follow the steps. I will try this and report back.
Go to this link and learn how to create an Ant build file for IntelliJ IDEA
Go here to download yGuard
Unpack the yGuard archive and navigate to the doc directory.
There is an html "how to" file. Read up on that, and you should be ready to release minified code.
Optional: search the net for yGuard tips & tricks to get the most out of your builds.
--- WORKING-NOTES ---
[1.0] In IntelliJ 2017, there is an option to generate the Ant Build File on the build menu. Build->Generate Ant Build File The settings that work for me are single-build-file, with everything else checked, using the supplied project name.
[1.1] View->Tool Windows->Ant Build this should get you where you need to be with the knowledge you got from the 5th step of the link at step 1 and step 4 of this answer.
Here is my working yGuard task:
<target depends="artifact.project" name="yguard">
<taskdef name="yguard"
classname="com.yworks.yguard.YGuardTask"
classpath="yguard.jar"/>
<yguard>
<inoutpair in="${temp.jar.path.project.jar}"
out="${artifact.output.project}/project-release.jar"/>
<shrink
logfile="shrinklog.xml">
<keep>
<class classes="protected"
methods="protected"
fields="protected"/>
</keep>
</shrink>
</yguard>
Then you modify your "all" to look like this:
<target name="all" depends="build.modules, build.all.artifacts, yguard"
description="build all">
<!-- Delete temporary files -->
<delete dir="${artifacts.temp.dir}"/>
</target>
And you have to REMOVE the delete temporary files action from the build.all.artifacts target, so when you get to the all target, the files are still available.
Just like it says in the yGuard html doc at the bottom, IntelliJ will complain about your yGuard syntax, but yGuard will still work.
If anyone can clean this up, feel free. It works for me, your mileage may vary. Also, you WILL be able to create a really tiny ant build xml, and use the Project Structure->Artifacts->Post Processing, after you have added your "tiny" ant build as noted in WORKING-NOTES: [1.1] "5th step". Some hand-hacking will definitely be required for this.
Related
lately I am getting this error from eclipse:
"invalid resource directory name", resource "crunch", type "Android AAPT Problem"
what is this problem and how to solve it?
Fix:
from the menu click Project->Clean...
a popup window will appear. select the check box for the project that is making this issue then click OK.
wait and see, that is it.
Ant and the ADT Plugin for Eclipse are packing the .apk file in a different build chain and temp generation folders. Crunch is created by the ADT. Best to do is to start every step with a clean if you switch between the tools. use ant clean if you used the ADT from eclipse before. Use Projects -> clean ... in Eclipse if you used ant before. Hope this solves your problem. Also restarting Eclipse could help.
I had the same issue: invalid resource directory name: D:\work\merge\Client_2_24\Client\bin\res/crunch. I tried Project->Clean but didn't work. Then I directly deleted the directory crunch and it worked :)
This problem is resulting of and Android requirement that in res folder only can have drawable, drawable-xhdpi, and so on. crunch is not one of this.
It's commented here.
https://stackoverflow.com/a/7168818/2411379
First of all, I find that this annoyance manifests itself when alternating between building my code in Eclipse and building it via ant on the command line.
The solutions that involve cleaning the project(s) are fine, however, my source tree takes more than 5 minutes to build given the fact that much of the code makes heavy use of templates. I try to avoid cleaning whenever possible to keep from having to do a complete rebuild. So here's my solution:
Add the following to build.xml:
<target name="-pre-build">
<delete>
<fileset dir="${basedir}" includes="**/crunch/**"/>
</delete>
</target>
This delete task in ant will recursively remove all crunch directories beneath the directory where the build.xml file is located. This task will run whenever I do an ant debug/release on the command line, which means I'll never have to clean my project as a result of this crunch nonsense again!
I could solve this issue by doing "ant clean debug". The above suggestions of cleaning the project from Eclipse didn't work for me.
If you don't want to use eclipse and get this error message with ant release -Dsdk.dir=$SDK_ROOT, you can just run ant clean -Dsdk.dir=$SDK_ROOT
This happened to me when I incorrectly imported a project to eclipse using "New Project ->Android Project from Existing Code".
It caused the crunch directory to turn up somewhere unexpected.
Importing using "Import -> Exising Projects into Workspace" solved it.
create a file called ant.properties in the folder where your manifest file is.
add aapt.ignore.assets=crunch:(whatever the default values are in your android sdk/tools/ant/build.xml file commented above the property )
when using cordova from the command line it uses ant
when using eclipse it uses android package manager
package manager compresses the png files and puts them into crunch, crunch is an invalid folder name for ant, if eclipse is set to build automatically, everytime u delete crunch it will be built again by the android package manager. you can test this by right click project, propteries, builders, unchecking android package manager, deleting crunch folder, and it will never come back again, you will also never have compressed png files again.
deleting the folder without doing any of these things and with eclipse open is just rolling the dice, will eclipse auto generate the crunch before cordova gets to the package-resource stage
when I updated android SDK build tools to version 18 and 19, I had the same issue.
My solution is:
go to google service library project - properties - builders - uncheck all builders
delete all the files under bin folder
run ant task to clean this project.
I believe the problem was that eclipse would build automatically, and generate files that are conflicted with ant build.
First of all try to Clean your project. If it works then well and good otherwise move into
the bin -> res -> there is one folder named Crunch. Just delete that folder directly and clean the project again.
It will solve the problem.
while my error is
Error:Execution failed for task ':app:mergeDebugResources'.
/path/to/project/app/src/main/res/drawable-xxdpi: Error: Invalid resource directory name
notice "drawable-xxdpi" is not valid folder name, while "drawable-xxhdpi" is right.
Some of yours folders' names might not be allowed by the Android standard: check the folders you made, and rename them.
I wanted to learn Java, as recommended by most of the people I downloaded "Thinking in Java" eBook and Source Code Example Lesson files from mindviewinc.com it's download location is this http://www.mindviewinc.com/TIJ4/CodeInstructions.html
These files don't work with Eclipse IDE for some reasons. So we have to build the files using the Build.xml file included in it's source code (Honestly, I do not have any idea what does "build" means here)
I tried building myself but of no use.. It did started building but after reaching some folder it stopped and gave error to install jboss-osgi-installer-1.0.0.jar .. After downloading it, I had no idea what to do with it, so I double clicked it and it asked me the location to install and I installed it in the default location, which was C:\Users\Username/jboss-osgi-1.0.0 and when I tried C:\Program Files\Java** the installation gave error that "this directory cannot be written, please choose another directory!" but anyway I installed it in the default location and it installed..
and again when I tried to build it, it gave me the same error and asked to Install Jboss....... I'm stuck.. This is happening again and again, wasted many days and didn't even crossed 100 pages of it's pdf because of this reason. It's a good eBook though.
I'm stuck in this from months... Please some one build it and make it like a project which could be easily and send me the project file, it would be really appreciated as I can not the solution to this anywhere on search engines..
Ok here's what I did to succesfully import the sources found in the "accesss" folder of you code samples:
Download the javassist jar as per Bruce's instructions, from here:
http://repo2.maven.org/maven2/javassist/javassist/3.9.0.GA/javassist-3.9.0.GA.jar
You must create an Eclipse project for the sources that are used as dependencies for most of the examples, that's the sources in the "net" folder:
in eclipse make new java project.
select the "net" directory, copy it, then in eclipse select the "src" entry in the project you just made, right click on it and select paste.
after eclipse finishes and auto-builds, it will complain about the missing javaassist jar. Right click on the project ->properties->java build path (on the left)->libraries (on the top)-> add external jars... (on the right), browse and select the javassist jar from where you down load it.
now the "net" project should be ok in eclipse
Now let's create the project for the sources in the "access" folder:
create a new java project in eclipse
Now, because Bruce structured his classes like crap, we'll have to make the proper structure in eclipse for them. This means:
a.create a new package called "access"
go to where your the access folder is on your drive, open it, select ONLY the folders (cookie2, desser, mypackage), copy them, then return to eclipse, right click on the "access" package u just made and click paste
now go back to the access dir on your drive, select ONLY the .java files (all of them, not the dirs), copy them, the back to eclipse, click on the src entry in the access project and click paste.
The access project in elcipse will still complain about missing classes form the "net" resouce. Right click on the project in eclipse->properties->java build path->projects (on the top)-> add(on the right)-> check the net project you created earlier-> click ok twice.
Now it should be ok
I hope you got the idea on how dependencies work in eclipse with this example.
For the other parts of you code samples, create separate java projects, add the classes to the proper package (create the packages if Bruce forgot to), and if you are missing external jars, go to http://search.maven.org search and download the jars. Good luck
"This code is designed to work outside of IDEs. Because packages are not introduced until later chapters, and some of the fancier IDEs like Eclipse require all code to be in packages, if you want to use the code inside those IDEs you will have to make some adjustments" - yep, bruce eckel would say that, cause that's the kind of guy he is. He also said there's ONLY checked exceptions in java, and asked for unchecked exeptions to be added as a bonus.
Now, if your sample code has no package, aka it's in the default package, aka when you look in the .java file, right at the top there's no line saying "package what.ever.bla" then all you have to do is:
-in Eclipse create a new Java se project
- open a windows explorer, go to your .java files, select them and copy them
- then in eclipse, right click the src folder in your project and chose "paste"
The files should be added to a "default" package in your eclipse project, without any error
Here is the simplest steps that I find to create a clean Eclipse project for the TIJ4 source code:
Download the source code zip from: http://www.mindviewinc.com/TIJ4/CodeInstructions.html, and unzip it to a folder, say 'TIJ4-code';
Download the additional libraries as in the previous URL, copy tools.jar from your current JDK's lib directory, and put them into TIJ4-code/lib;
Go into the 'TIJ4-code' folder, and run 'python Eclipse.py' (you need python installed on your system). This script adds the missing "package xxx" line to those source java files which don't yet have them, so as to make Eclipse happy. It also generates the Eclipse project files, which doesn't work well for some reason (beyond my limited knowledge on Eclipse), but they aren't needed here;
Open Eclipse and create a new empty java project, say with name 'TIJ4', choose JRE version 1.5, and "create separate folders for sources and class files";
Copy TIJ4-code/lib directory to your new Eclipse project folder;
Right click on the new project and select "Build Path" >> "Configure Build Path", then go to tab "Libraries", "add jars", then select all the jars under your project's lib folder;
Go to "File >> import", choose "General >> File System", select the unzipped folder 'TIJ4-code' as your "From directory". Check the root 'TIJ4-code' in the left panel of the import window, Click on "filter types" and select the .java, so that unnecessary files of other extensions, like *.class, *.py, *.xml, etc can be ignored during the import;
The zipped folder is no longer needed after the new Eclipse project is built. I hope you find this instruction helpful, and have fun learning TIJ4.
If you want to use this code in IDE rather than Eclipse and so on, for example in Intelij Idea or any other, the best way is to compile necessary classes from the TIJ4 with Ant, but it is not easy for the beginners, although it will be a good practice for you. You should make some changes in build.xml files which exists in every directory of TIJ4. Why?
to change version of Java(now we all use Java version higher than 1.5)
to include javaassist.jar library in the "classpath"
to put all compiled files in 'bin' directory(by default without adjustments TIJ4 build.xml puts .class files in the same directory with .java files. That is not a good deal.
For example you need to import and use within IDE(I use Intelij Idea) the class named net.mindview.util.Print ( see Chapter 3):
download TIJ4 and unzip in any directory you want(for example it would be c:\eckel)
download and install AntApache (you can find detailed instructions how to do it in Google) The result is - type in your console ant -version and you should see the answer. So Ant is working.
download javaassist.jar from http://jboss-javassist.github.io/javassist/ . Unzip to any directory, take out javassist.jar and past it to c:\eckel\net
4.There is build.xml file in c:\eckel\net. Now you should make adjustments. Open it with NotePad++ or other editor.
If you don't have Java 1.5 installed on your PC, so change all 'vesion1.5' to 'vesrion1.8' or other version that you have installed.
after tag description put property name = "classpath" value="./;./javassist.jar"/>
<property name = "src_util" value="./mindview/util"/>
<property name = "src_simple" value="./mindview/simple"/>
<property name = "src_atunit" value="./mindview/atunit"/>
<property name = "destdir" value="bin"/>
Then we make targets that will complile util simple or atunit automatically
Change tag available <available
classname="javassist.bytecode.ClassFile"
classpath="${classpath}"
property="javassist"
/>
Now classpath of available = property named 'classpath'. Classpath is the path where java compiler looks for .class files because some of your .java files want them by having import statement. There won't be error message "You must install the Javassist library " any more
Create targets for compiling util simple and so on See the following link with code
Code with targets
You can modify exists targets not to write all the code.
at the top of build.xml file change default="simple"
open cmd, then cd c:\eckel\net , then ant -simple or just ant (simple will run as default)
Please write if you will have some problems. Possibly i forgot mention about something.
Go to Intellij Idea, press Ctrl+Alt+Shift+S
Press +,
Library or directories
choose your c:\eckel\net\bin
5.now you can use import statement for all classes that exist in net.mindview
6.you can make the same with other dirs.
If you wish to you skip the entire Ant build process, I have converted the project to a Maven project (over JDK8), which you can simply import into your Eclipse workspace.
https://github.com/gauravojha/tij4-maven
Thanks to #Sergey Oliv's example. In addition, I needed to provide uncompiled javaassist package with all java files in the 'net' folder too. The .jar wouldn't work by itself.
I must say, this was a lot of work to get going.
I have been given an application which uses a build.xml file for building purposes. I have very little knowledge of Apache Ant and the classpaths seems to be the following:
<!-- Classpath -->
<path id="development-classpath">
<fileset dir="${libs.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="."/>
<pathelement location="${classes.dir}"/>
<pathelement location="${configuration.dir}/langs/"/>
<pathelement location="${fits.dir}/xml/nlnz"/>
</path>
As I want to use Eclipse own building facilities I would like to assign these classpaths variable in Eclipse, which I don't have much experience with. How do I do it?
Go to your external tools configuration, select your ant build, and click on the Properties tab. You will probably have to un-click "Use global properties...". Then it is simply a matter of adding properties. This will allow you access to the variables built into Eclipse such as ${project-loc} and these properties will be available to ant as if you had set them in the ant file itself.
Here's the manual way to configure Eclipse to mimic what ant will do using the build.xml file. This should get you started:
Open Eclipse, open the "Java" Perspective. Right click the project and choose "Build Path / Configure Build Path". Alternatively click "Project" Menu, and choose "properties", then click "Java Build Path". Click the Libraries Tab. This is where you tell Eclipse where the jars needed build your project are located.
From the build.xml snippet, the first "<fileset>" specifies that all the jars you need are under the <project>/libs directory (I'm guessing that ${libs.dir} corresponds to "libs" but you might want to double check. It should be defined near the top of build.xml). So click, "Add Jars...", navigate into <project>/libs, highlight all the jars inside the directory and then click "Ok".
The first and second <pathelement> tags are telling ant to use the current directory and the classes directory. Eclipse should already take care of this by default, but to double check, click on the "Source" Tab (should be in the same "Java Build Path" dialog as the "Libraries" tab). The default output folder shows where eclipse will compile java code to .class files. The Source folders on build path shows where all your source code is that Eclipse should try to compile.
Finally, The last two <pathelement> tags tell ant to use some resource/config files under ${configuration.dir}/langs and ${fits.dir}/xml/nlnz. You can add these similar to the way you added the jars. Click "Libraries" Tab. Then choose "Add Class Folder" and highlight both the "langs" and "nlnz" folders.
Hope this give you some insight into where Eclipse looks for jar dependencies, class files and resources.
Having said all this, as you become more familiar with Eclipse and build tools, you'll probably discover that this probably isn't the best way to go because it's very easy for the build.xml and eclipse configuration to get out of sync. There are ways to tell eclipse to build using an ant build.xml file (check out File->New Project->Java Project form Existing Ant Buildfile). And there are also ways to run ant targets from within Eclipse (check out Window -> show view -> ant).
Probably you need to put build.properties files at same path which build.xml is.
This build.properties will looks like similar to this:
libs.dir=path_where_libs_are
classes.dir=path_where_classes_are
configuration.dir=etc
fits.dir=etc
This will allow to run your ant script with these configuration values inside and outside Eclipse.
I have a sample code that was built with Netbeans.
It has a build.xml file so I downloaded ant and try to run it.
I've got this error message:
...... nbproject\build-impl.xml:76: Platform is not correctly set up
For what I can see, this is fixed by "simply" downloading Netbeans and running the sample from there, but... I don't want to install it to run a 10 files sample.
Is there a workaround to run Netbeans projects with Java? What's the correct .properties file I have to modify?
It is possible to run the NetBeans generated projects straight from Java/ANT, but you may need to manually set some of the properties and/or add paths to jar files.
Unfortunately, NetBeans tends to include taskdef's using their own JAR files and reference properties that are defined only in the /nbproject/private/private.properties files, which usually get set when you first open the NetBeans project or modified as you edit the project in the IDE.
If you inspect the build-impl.xml you should be able to find the property and derive what value needs to be set(OS platform), then either:
create/set the property in the
/nbproject/private.properties
add that property definition in the
parent build.xml
pass in the commandline when invoking your ant
target using -DPlatform=Foo
Personally, I like the structure of the NetBeans generated ANT files and targets, but hate how much custom/proprietary stuff they jam in that makes it hard to run without NetBeans.
For example:
ant -Dplatforms.JDK_1.7.home=/opt/jdk
I've just successfully built NetBeans project with ant. These were the things I had to do:
Copy <NetBeans-folder>/java2/ant to a "Netbeanless" machine
Copy nbproject/project.properties to, say, ant.properties
Replace every ${} expression in ant.properties with it's value
Add platform.<platform-name>.home=<path to platform>
Add libs.CopyLibs.classpath=<path to nb-ant>/extra/org-netbeans-modules-java-j2seproject-copylibtask.jar
Add other needed classpaths into javac.classpath (e.g. path to servlet-api.jar)
ant -propertyfile ant.properties
It works, but doesn't make me happy. I would either like to find the way to reuse project.properties, or to automatically translate it to a "resolved" version (step 3). Build could then be automated.
I just went through this exercise with my NetBeans 7.0 project. What I was able to do was copy my build.properties file from my .netbeans\7.0 directory on my Windows system and make a server.properties file for my build server. This isn't much of a stretch, since every developer's build.properties may vary, so having another file for the server is to be expected. I then put together a simple server-build.xml file that references this file and does only the basics of init, compile, dist, and clean. I committed these two files to my CVS repository at the top level of my project directory, since they don't conflict with other project files and serve as a reminder in case something needs to be updated. Now I can build my project on my CI server with "ant -f server-build.xml" and everything just works.
My whole init section looks like this, giving my server paths priority, but including the necessary information from the NetBeans project properties.
<target name="init">
<property file="server.properties"/>
<property file="nbproject/project.properties"/>
</target>
I also had to do something similar when defining the ant tasks for my nested projects:
<target name="compile">
<ant antfile="${project.MyProj-common}/build.xml" inheritall="false" target="jar">
<property location="${build.dir}" name="dist.ear.dir"/>
<property file="server.properties"/>
<property file="${project.MyProj-common}/nbproject/project.properties"/>
</ant>
...
</target>
I had to copy the j2ee.platform.classpath from project.properties to my server.properties file to ensure the references to j2ee.server.home resolved as I needed. I didn't expect to have to do this, but the classpath was wrong otherwise, causing the build to fail.
Thanks for the information on this question, as it helped guide me to this solution.
I just faced the same problem. I hope I could get rid of netbeans to go to eclipse and maven, just for that.
But here is a good link to export a ant built project from netbeans into a continuous integration server (or could be into any other IDE too).
Technique is going pretty well. Here is a summary:
install netbeans on the CI server (there is an option to do it without gui, use -silent on the netbeans installer)
include nbproject in SVN
add to ignore list the private folder
create your own private folder on CI server
make it point to a folder of your CI server (mimicking a private user folder in the account used for CI)
copy a real folder from a user to this folder and change every path (replace strings) to point to your netbeans install on your CI server.
And it should work.
Just to add to Mads' answer... usually, you need to install and open Netbeans at least once on the target machine. The ANT projects also rely on a few settings from the USERDIR/.netbeans/... directory. This may have changed with 6.5+.
This will get some of the base settings configured and define the classpath's to netbeans jars. If your dependencies (i.e. libraries) or project is being run from a different directory since the last time you opened the project in Netbeans, you will need to tweak a few settings in the private.properties file as Mads' described.
I'm using Netbeans 6.8 and java projects that were created with Netbeans can be run from the Netbeans auto generated build files with just ant on the cli. All the regular targets like ant compile,ant run,ant clean, etc "just work". (I'm using Fedora 13 if that matters)
You can use this repo just for that https://github.com/albfan/ant-netbeans
It overcomes all the oddities of netbeans wrapped ant config so you just need:
To compile:
$ ant.sh compile
To run:
$ ant.sh run
To whatever (autocompletion):
$ ant.sh <tab><tab>
This problem has been frustrating me for some time...
A lot of sites like Sourceforge use SVN or Subversion to manage their code. I have little problem compiling SVN code in C++, but when it comes to Java, my IDE gives me a headache.
I've installed Subclipse for SVN support for Eclipse, and it works. I can check out any code into my Workspace. Now Subclipse will put the whole thing into a special project of some sort that can't be compiled. So I search Google for something and I come up with modifying the eclipse XML file to specify the 'nature' to be a Java project.
Okay, now it's a Java project. Say I have a folder structure like:
\src
\data
\graphics
I get 800 compiler errors complaining the package name is org.company.SomePackage instead of src.org.company.SomePackage.
Then what I do is create packages called src, data, graphics, etc, instead of just folders. I cut and paste everything in the folders into the packages and finally I can compile it.
What is a better way to do this?
EDIT: I can only check out anything SVN as a SVN project, and there's no way within Eclipse to change that to a Java project. How can I check out the SVN as a java project in the first place?
I get 800 compiler errors complaining
the package name is
org.company.SomePackage instead of
src.org.company.SomePackage.
Right click on Project -> Properties -> Java Build Path -> Source Tab -> Add "src" as a source folder and remove any others.
it thinks your source is stored in root folder. you need to specify to the project that /src is the source folder.
In general when we have an Eclipse project, which contains Java code – but we didn’t set it up as a Java project when we created or checked out this project, we are struck. And Eclipse doesn’t allow to change the project type inside the Gui. So we need to add the java nature as below.
1. Close your project.
2. Open your project file (which is located in your root directory of the appropriate project) called .project with your default editor. Search for
< natures>
< /natures>
and change it to as below
< natures>
<nature>org.eclipse.jdt.core.javanature</nature>
< /natures>
Save the changed file.
3. Open the project again – now it should become a java project.
Then do the following as explained by Kevin
On the Project Explorer Window ->Right click on the specific Project -> Properties -> Java Build Path -> Source Tab -> Add "src" as a source folder and remove any others.
For me when I went into “Source Tab” – the “src” folder was already added, but it was not giving me the desired result (ie I was still not seeing the .java files in the project explorer window). So I removed the “src” filed that was already added in the Source Tab and then added them again. And then all worked fine.
You have to configure proper source paths. Some open source projects make this automatic by checking their .project and .classpath files in with the rest of their files. For others, you'll have exactly the problem you are having. You need to set the classpath so the Java compiler knows where to find the source. You right click on the project and select properties and configure an arbitrary classpath, but the answer given by Kevin is easier for a beginner.