Ant script with eclipse [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Want an eclipse java project to run ant build files automatically
I wonder if it´s possible to write an ant script that creates a build(jar-file) automatic every time some modicifation is done in my project(repository)? If it´s possible anyone one that can help me or link me some good pages for this.
Thank you!

Have you considered the Ant task uptodate. This allow you to compare timestamps on a set of files to another. In your case you could compare all your src *.java files for example to your output jar. You would then be able to have this running in a loop which would give you the desired effect. Albeit in a fairly crude way.
This also has the benefit of not actually doing any work unless the src files have changed and can be applied to compilation as well to produce a java incremental build, that comes for "free" with other build tools.

Related

Is it necessary to execute mvn clean before mvn compile? [duplicate]

This question already has answers here:
In Maven, Why Run 'mvn clean'?
(4 answers)
Closed 4 years ago.
If I want to re-compile the project, should I execute mvn clean first?
In most of the cases you can skip clean. However you should keep in mind possible side effects can be caused by "dirty" target directory. E.g.
You completely removed some class/file, compiled version gonna live in target
In real life project it is quite often to use external plugins during the build, which can also generate some files/reports/etc. From my experience plugin developers don't care a lot to handle situations with "dirty" target folder (I would do the same :)), so you can get tricky errors during the build.
So I would highly recommend to always use clean:
Before publishing the artifacts
When you get some unexpected behavior/errors during compile/package
Most of the time yes,
When deleting resources, classes or anything which lead to something created in the target directory then a clean is necessary because the item won't be deleted until then.
If not, the generated artifacts may contain those deleted items.
If you only updated existing items then most of the time you can bypass the clean
EDIT:
Be extra careful with my last statement. Even updates can lead to side effects without clean. What if a plugin generates items with hash in their names ?
#See In Maven, Why Run 'mvn clean'? for more issues than can arise without clean

Difference between make and build in the Intellij idea [duplicate]

This question already has answers here:
Difference between make and build in Android Studio
(3 answers)
Closed 6 years ago.
The Intellij idea in the build menu has Make Project and Build Project. what is difference between them?
You can get it on the Intelij site:
Make Project: All the source files in the entire project that have been modified since the last compilation are compiled. Dependent source files, if appropriate, are also compiled. Additionally, the tasks tied to the compilation or make process on modified sources are performed. For example, EJB validation is performed if the corresponding option is enabled on the Validation page.
Rebuild Project: All the source files in the project are recompiled. This may be necessary when the classpath entries have changed, for example, SDKs or libraries being used added, removed or altered.

Why is my project not compiling?

I checked out a new version of my project from svn and now Java has made the easy thing difficult. I don't know what is wrong and I can't even build the project. What should be done? The code should compile, it's just not being picked up by the IDE.
And I couldn't run it with Java 7 but that might be a different question, now I can't even run it with Java 6 since Eclipse has made the easy thing difficult. Did I do something wrong when I checked out the project from svn? I use xp-dev.com
You checked out the entire repository instead of just one tag. You wanted to check out trunk.
Right click on your src directory that contains your packages and specify Build Path -> Use as source folder and it will set things up properly for you.

Java/Ant - Compile multiple variations

I currently have a Java project in Netbeans 7.3, which contains a settings.java class. Within that class are 3 booleans that turn on/off various features of the program (eg: trial, full, etc).
Although it is one project in Netbeans, it actually produces 6 different versions of the program, which I currently have to manually create by editing the variables, compiling and copying, editing the variables, compiling and copying.... six times. This is rather time consuming and inefficient.
Is there a way for my to accomplish the 6 builds without manually editing->compiling six times?
Thanks!
----EDIT----
Thanks for the help! In case anybody has a similar question, I ended up writing a java class that modifies the settings file and compiles using ant.
My solution: https://gist.github.com/patopop007/5561428
Two possible solutions come to mind:
Create several NetBeans project. One will be a library which contains all the code common between all the different builds. Then create a new NetBeans project for each of the separate builds.
Create different custom ant targets in your NetBeans file for each build. For example
<target name="trial">
<!-- Stuff specific to the trial build goes here. -->
</target>
<target name="full">
<!-- Stuff specific to the full build goes here. -->
</target>
The specifics depend on the exact differences between the builds.

How do you use a Java project in your Android project in Eclipse?

I'm writing an Android application and there's some Java code in it that's somewhat sophisticated and therefore hard to verify the correctness of in the Android environment. I would like to run this code in a desktop environment where I have more tools with which to examine the output of this code while still using it in my Android application.
My attempted solution is to have three different projects in Eclipse. My Android project and two plain (non-Android) Java projects. One Java project has the sophisticated code that I want to use in Android and the other is a test program that verifies the correctness of the former project. The latter project has already been useful in debugging the former.
However, so far, my attempts to use the Java project in my Android project appears to work in the IDE but when I actually run the Android application, the NoClassDefFoundError exception is thrown whenever I try to access any of the classes. Obviously, that code is not being recompiled into the .dex file but why not?
I could go into detail about what I've done so far but I can't help but think that what I'm doing is a pretty standard and simple thing and there's a plain way of doing it, even though I can't find anyone doing quite what I'm trying. Can someone describe to me how this is done?
Luckily, I found the answer to my own question and I thought I'd share it here to help others in the same situation. It turned out to be very simple...
What I was already doing would have normally worked, which should have been a big clue to me since I have actually done this before, successfully. All you have to do is, under your Android project's Properties > Java Build Path > Projects, add the plain Java project to your "Required projects on the build path" and then under Properties > Java Build Path > Order and Export, check the checkbox of that same project in the "Build class path order and exported entries" list and everything should just work.
From within Eclipse, there's nothing else you need to do to get this setup to work. It's only when you're compiling from the command line that you need to build Java Jars and import them as libraries but I'm not doing that (yet).
Finally, this wasn't working for me because I just happened to be compiling my plain Java project under JDK 1.7 compliance, while my Android project was compiled under JDK 1.6. This is verified by the output on the Console pane, reporting "Dx bad class file magic (cafebabe) or version." This error message goes away when both projects are compiled under the same compliance level and, not coincidentally, the Android program runs properly.
Thank you to everyone who tried to help and I hope this answer is helpful to someone out there!
Would it not work if you made your other plain java project into an Android project and use it to monitor the output on the device?

Categories