Ant javac ignore missing imports - java

i am trying to port a build from Eclipse to use "standalone" ant, there are a lot of linked files/folders and also some cycle references(If i export via Eclipse it is working).
I was trying to find a way to make the javac ignore if a java file was not found.
Is this even possible with ant?
And if not, is there any chance i could be able to get a working build perhaps with an other build tool?
thanks in advance

I was trying to find a way to make the javac ignore if a java file was not found.
Don't. Instead, make sure you supply all the code you need.
What would you expect the compiler to do if you start using a type which it knows nothing about? Java just isn't designed to cope with the situation.
If Eclipse can build the code without errors, then everything should be available - you should track down every missing file rather than trying to ignore them.

Related

Javadoc cannot generate because of --source-path flag

I'm working on a rather large project in java thus the need for javadocs.
I'm using java 1.8.0_332.
My problem is that when I try to generate the javadoc with Intelij Idea Community 2022.2.
It tries to use the --source-path flag when generating witch fails because it isn't yet defined in java 1.8.
Is there a way to force Idea to list the files separately if not is there a way to give javadoc the specified files manually. (yes I know at this point I should be using a build system to automate such things but I'm not the one making the calls on what I can use)
I've tried the methods in this question to no avail.
As in the question mentioned above I've tried to generate the javadocs via the Tools -> Generate JavaDoc panel, witch returns this:
1 error
javadoc: error - invalid flag: --source-path
"javadoc" finished with exit code 1
This error is due to me using java 1.8.0_332. I cannot change this in the main code compilation due to my spec regulations. Nor does the project have any build system. Again due to the spec this would be rather hard to push through. (I'm aware that a larger scale project should have one)
My second attempt was to use a custom scope where all my .java files are present.
This resulted in the same output as above.
I've ran out of elegant solutions at this point.
As the project is rather large and old code handed down to me I wouldn't want to manually list these .java files (though with scripting that could be a solution).
Are there any elegant solutions that I'm missing?

Get ClassNames acroos Java Projects

I need to develop a Tool for checking certain Java Code conventions for all the java classes present in a Java Project.
For one of the rules(i.e;Checking the Class Name Convention)I need to get all the Class Names given the Folder Name.Instead of parsing it line by line,can anybody suggest me a better way to do the same.
NOTE 1: Reflection is not an option because it doesn't work across java projects.I can not use build path as well since there would be many projects at run time for which i need to check the code conventions.
NOTE 2: Currently,I ma using eclipse IDE to build this,but in run time I am not even sure whether they would be using only eclipse IDE.Hence,when you suggest any eclipse plugin ,please bear this in mind.
Thanks in advance:)

Eclipse: I'm using ANTLR4 plugin, How do I get Eclipse to build the artifacts created by the ANTLR4 plug in?

I have successfully followed the instructions from amura.cxg's Stackoverflow question/answer on how to setup Eclipse for ANTLR4 (Thanks amura.cxg!).
It works well, my .g4 grammar files are getting run through ANTLR4 fine. One downside is the ANTLR4 plug in has no option for setting the -package argument to the command line, but -listener/-visitor options are present.
My issue is... now I have these cool *.java artifacts as a result of using the plug-in. I want Eclipse to either build them in place, and allow my *.java code at the bottom of the screen to find the *.class files, or have Eclipse auto move/copy them to be sources in the *.java projects below (I don't care as long as it's automated and works).
I'm looking for a way to do this. I would hope I don't have to setup and install MAVEN.
Currently my *.java code which is dependent on the BaseListener.java classes won't build because the classes are not getting built.
Thanks!
I started with Linked resources and had some success, but it still wasn't perfect.
I found this information from
this StackOverFlow Questionwith an answer from srinivasan.
This is the screenshot to create linked resources. This was the method I wanted to understand.
There are two ways to create linked resources. One "add a Folder", this method I tried first, and was not exactly what I wanted, as it created an extra layer and forced the naming of the lcoal folder. By using the Properties tab, I was able to create a local alias for the resource. I think this will ultimately be the solution.
I'm still testing it, but I wanted to post my findings so far in case I get too busy to document my progress in learning later.
:)

Making a multi-class jar easier

I was working on a project with a seriously large amount of classes that I want to compile to a jar. I know about entry-points and the manifest.txt and all the needed items inside my jar, my classes are all compiled and have the .class file and everything, but the problem is I will have to add all the class files to the final jar in compilation through a single line in Command Prompt. I was wondering and stumbled upon literally nothing in the internet if it could be done in an easier way because I will be updating my work constantly and have to recompile and re-jarify my work. I have heard of third party programs that will do the trick, but somebody on some website said that they could potentially be causing problems and stuff, so I dropped the idea quite quickly. Now that I am in a seriously tight spot though, I wish to hear opinions and suggestions on this. So to sum up:
I want a way to compile a big bunch of .class files in a single jar without typing all of them over and over again between compilations allowing me to save time and frustration.
I would prefer native stuff if this is even possible to do - e.g. the jar compiler of the JDK instead of anything third-party. If there is a way to do this using manifest or any other file in compile-time arguments, let me hear it.
Anyone who cares to suggest, discuss or give me a good reason why to or not to use third party applications for this will be most welcome.
Keep in mind that I work on Windows but my aplication will be cross-platfrom, so don't suggest as a main option some compile solution that will make a final file with a .exe extension (although if anyone knows how to do this, I would like to hear it in a comment as I wonder about this as well).
Thanks in advance and if you feel the need to ask me anything to help you reply, shoot away!
Have a look at this ant tutorial which shows how to write a simple build.xml which can compile and jar.
http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
You can then adapt it for your own needs.
Note: ant is only suited for smaller projects like yours.
The solution to this, and related, issues, is to stop typing at the command line and use a build tool. The common tools here for Java builds are:
Apache Ant http://ant.apache.org
Apache Maven http://maven.apache.org
There are other less common ones. Both of these tools will provide you with what you need.
Just want to add some information about Ant and Maven.
In your case, you need to automate the build of your application. The basic solution would be some kind of script but it's not used at all. Nicer solution exist :
If you come from the idea of a script to automate your build, you can use a tool like Ant, it's a bit like make and such tool in the C world where you define the needed tasks for your build in a configuration file. The problem with such solution is that it allow you to define your own structure for your build and a new comer to your project may have some difficulties to understand the logic of the build.
The other approach is to describe what kind of build you want to do, organize your sources and resources as it is done in most cases (by following a convention in fact). For example, java sources are in src/main/java, tests are in src/test/java, config files are in src/main/resources, and so on. In the description of your build you will just say : this is a java project and I want to build a War web application and execute my tests using jUnit 4. The dependencies of my project are apache xerces and hibernate 4. Then, the tool will know what to do without the need to say how to do. This is the way maven do.
In short, in the Ant approch, you will say how to do what you want and in the Maven approach you will define what you want to do and the tool will know how by default.
You may also be interested in some kind of hybrid approache like the one provided by tools like Gradle.
For more information :
http://ant.apache.org/
http://maven.apache.org/
http://www.gradle.org/
Hope it helps

Compiling Java file with code from within a Java file

I'm currently creating a personal (maybe public) java terminal. I want to create a command that will create + compile a Java file on execution, except I'm not too sure on how to actually do this. Is it possible? Or am I just dreaming?
You could also use Groovy - it's quite handy if you just want to compile and run a line or two of Java code from within your application. The application may be in regular Java, with Groovy used only for compilation of the dynamically generated code. Whichever solution you choose, be careful, as executing user input as code can lead to security issues (vulnerability to injection attacks).
compile a Java file
See the STBC. It uses the JavaCompiler to compile the code in the text area.
I agree with #eee's comment that javax.script is probably a very nice fit for your project, script code is easier to deal with than Java code. I've successfully used it in the past for a plugin API, I don't remember having had any problems to get it up and running.
Most projects that I know of that compile real Java at runtime use the Eclipse compiler to do so. The Java 6 javac can be accessed completely programmatically as well. I've never used either of these myself. These two and some other compilers can be accessed via Commons-JCI if desired.

Categories

Resources