Android: Include External Jar in Build (Without Eclipse) - java

I'm working with Android at the moment, trying to avoid using Eclipse (for which I have an irrational hatred).
I need to include an external .jar file (used in my Activity)and have no idea how to link it for ant debug...
I've read up on build.xml files but adding <path id="compiler.classpath">...</...> or <classpath> nodes to the XML doesn't help fix it.
Hope someone can help me out!

Just put it in the libs/ directory. Everything else is taken care of from there -- no Ant script modifications are needed. For example, here is a sample project showing integrating a BeanShell interpreter this way.

Related

Google OR-Tools: Using in an IDE

I have the Problem that i want to add OR-Tools into my project via eclipse IDE. I want to use the Linear Solver. I added the two jars form the downloaded Zip file. Now i want to run the SimpleLpExample from the OR-Tools site. I've got the Error that no jniortools in java.library.path. I see that at other posts they say you have to run make third_party and make java, but i don't know where i have to run these commands.
When somebody added it successfully into an IDE it would be glade when this person can explain how he does it. Thanks for help.
No. You need to add the path to the jniortools shared library I'm eclipse.
All dynamic libraries are located in the lib/ directory of the extracted archive.
To add the correct path, please follow these instructions:

How to use proguard on intellij IDEA?

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.

Can't export java project with a working run configuration using Eclipse/Gradle

I'm trying to learn how to program with Java using Eclipse. For this I'm trying to do a Minecraft mod project since I'm actually a gameplay programmer. I just recorded a video to show you what are my problems:
Here
Maybe some of you will see the problem I have. Thank you very much and have a good day :)
PS: I can edit and add some code if It's gonna help.
I am increasingly convinced that you need to add a MANIFEST.MF to a META-INF/ folder in your project. The issue being stated is that Java cannot find a Main class after the jar has been built, though we have seen that the application can run when Eclipse starts it (and Eclipse was told where the main class was.)
I would start here and begin gathering information on how to build a manifest file that will include the information you need.
Use of the MANIFEST.MF file in Java
I will be busy for the next couple of days, but will try and keep an eye here if you have follow-up questions.
Edit: Some more information after reviewing your video. Does your Naruto project rely on the forge project, or does the forge project rely on the Naruto project? If I am understanding this correctly, I think your build.gradle file needs to list forge as a dependency
compile project (":forge")
the ":forge" part indicates that forge is in the same directory structure as the Naruto project. You can then rely on Gradle to create the jar for you. Gradle is an amazing tool and, when possible, you should leverage Gradle in your development (since you have it built into your project already.) You can also tell Gradle to generate a MANIFEST.mf file when it creates the jar. See this link for creating a jar / manifest with Gradle.
http://www.mkyong.com/gradle/gradle-create-a-jar-file-with-dependencies/

How to Make Java .jar files be automatically found in any environment

I am trying to add an external library to my Java project. The library files are in .jar format, and every time someone tries to run the project in a different environment, they have to modify the build path so that their environment can find the .jar files.
Is there any way to make it so that the .jar files are automatically found by the build path? Maybe by specifying where in the project the .jar files are located?
Edit: Here is an example -
In my linux environment, the .jar files are located in:
/home/MyUsername\SomeDirectory\workspace\java_project_name\data
In my windows environment, the .jar files are located in:
C:\MyUsername\SomeDirectory\workspace\java_project_name\data
In the example above, the project root directory is "java_project_name", and the .jar files are always in the java_project_name\data folder. Even though this is the case, different environments can't seem to detect that it is always in the same path in relation to the project's root directory.
I have looked in many places on how to do this, and some people told me it isn't possible. This doesn't sound reasonable to me, which is why I am posting this question here.
Thanks in advance for your help!
you can add a ClassPath: entry in your manifest file of the main jar, and use relative paths. As long as the jars are found relative to the main jar it will work.
This issue was one of my main motivators to start using maven.
#YoK nicely quotes here the relevant reasons to this question https://stackoverflow.com/a/3589930/1493954
Here is one the relevant quotes from Benefits of using Maven
Henning
quick project setup, no complicated build.xml files, just a POM and go
all developers in a project use the same jar dependencies due to
centralized POM.
getting a number of reports and metrics for a project
"for free"
reduce the size of source distributions, because jars can
be pulled from a central location
This is a common problem for developement environments.
I myself use the following solution in netbeans [Hope so that it works in your IDE too]:
Create an Ant variable [for e.g. JAR_LOCATION].
Each and every JAR that you refer, must have it's location relative to JAR_LOCATION.
Now, in every development environment that you're gonna use, you can set up the same ANT variable and it'll automatically pick up the JAR.
You can see the example in the given snapshot of netbeans..

Run NetBeans project just with ant

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>

Categories

Resources