Get ClassNames acroos Java Projects - java

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:)

Related

How do i link a compiler to an editor

So i have tried to find an answer but didn't manage to do it yet. What I'm trying to do is to write a Java code for example in Atom editor, and compile it on Atom itself, without the need of an integrated development environment. Same goes with adding classes to a project.
Is that possible?
Yes. That is how they wrote the first Integrated Development Environments. Although the compilation step is typically performed externally from the editor, if the editor can execute external programs then you can "integrate" compilation. Adding "classes" is a little more involved, in that it requires your "editor" to understand the packaging and structure of the files composing the classes - at that point you have an integrated development environment.
Yes it's possible with atom package build. To install the package Edit-->Preferences-->Install and type build and hit Enter. Then you should configure your custom build command as mentioned in official package website. You may just fill cmd: javac in yml file for example
You need to install a package that will compile. Atom is a hackable text editor but not really an IDE as you pointed out. That said there are a lot of packages for compiling and for working with java.
You can look at Build Tools Package for compiling. It looks like it will work for Java but there are many compilers in the package list.
I would search on their package site for the keyword "Java" to see what java packages you might want to use. Then do another search for "Compile" to see what compiler you might want to use if the build tool above doesn't work for you. You can search atom packages at https://atom.io/packages.

Create a Java class from a groovy test file in IntelliJ

Trying to do TDD in a java project using groovy tests, I need to generate java classes on the fly (Alt+Enter from the test on the name of a class I want to introduce -> Create class -> Select the java main package as Target destination).
The problem is that, even if the Target destination is a java source directory, IntelliJ generates a groovy class.
Is there any way to quickly generate a Java class, instead?
With the current version of IntelliJ IDEA (2016.2.4) the only solution I found is to generate a groovy class (Alt+Enter| Create class from the test) and then convert it to Java (Refactor | Convert to Java).
To make it faster I also added a shortcut for Convert to Java: Ctrl+Shift+O was the best available option for me.
Looks like now it's not possible.
This guide is exactly for this TDD workflow and there are no mentions about it.
Also I made research through IntelliJ's issues and didn't find any similar task.
And finally I post feature request for that.

Ant javac ignore missing imports

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.

Beginner Java Developer Netbeans/Eclipse IDE Questions

Im working on building a java application in windows vista using the Emotiv Epoc Neuroheadset, http://emotiv.com/index.php.
I'm new to java and having a really tough time getting started. I have some examples that came with the headset I'm trying to run in either eclipse or netbeans (at this point I really don't have a preference, suggestions?)
The user manual gives these directions:
*2. Package content: Jna.rar, Edk.java, EmoState.java, EDkErrorCode.java
Example 1: EEGLog
Example 2: EmoStateLog
Developer‘s guide: Step 1: Add the JNA library to your project. Step 2: Add Edk.java, EmoState.java, EdkErrorCode.java to your project. The classes in these files contain methods calling the APIs from Edk.dll using JNA library. You can find more information about the conversion between data types on the JNA's homepage.*
This is all Chinese to me! Can someone explain to me exactly how to do these steps (in a way a small child who have never used eclipse or netbeans before can understand!) Somebody from the Emotiv Epoc forum gave me these directions as well:
*To see how to Java wrapper examples work you should install Eclipse and open, compile them. You put edk_utils.dll and edk.dll into System32 or the same root directory of each example as EmoStateLog, CognitivExample,... before running them.*
My problem is I dont know enough about the IDEs to run these examples. Am I supposed to make a new project then add these files? Or do I open one of the examples, then add the .dll files and the JNA library? How do you add libraries to a project? Where do I put the .dll files?
Thanks in advance!
I know this is fairly simple stuff but its always the simple stuff thats hardest to figure out it seems!
-Eric
Based purely off of what you're saying here...
Developer‘s guide: Step 1: Add the JNA library to your project. Step 2: Add Edk.java, EmoState.java, EdkErrorCode.java to your project. The classes in these files contain methods calling the APIs from Edk.dll using JNA library. You can find more information about the conversion between data types on the JNA's homepage.*
Create a new project in Eclipse.
Add Edk.java, Emostate.java, EdkErrorCode.java into the src folder
Add the JNA library into the libs folder. (Make sure the library is in the project path, otherwise Eclipse won't detect it.)
Whether or not it will compile depends on if those are the only supporting files.

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

Categories

Resources