I want to create one external jar for Logging Purposes,so that i can import this jar in any java project.But i would like to use the classes and methods of java project in external jar.
Is it possible ?If yes,please help.
I think it's possible from Reverse Engineering,but not able to figure out how to use class and specially methods in external jar.
It is possible, but very bad practice.
You need to import each project into eachother.
Project A imports Project B
and
Project B imports Project A.
I would recommend you to use eclipse and add the projects as source. You can read how to do that here:
Creating a java library with Eclipse
You can read about the bad practice of what you ara about to do here:
Two java libraries importing each other?
Related
I am trying to learn java and have implemented a single, and simple, class in Intellij IDEA 14.1.3. I want to be able to use this class in other projects without copy and pasting the class source into each project src directory. Essentially, I want to create a package, or module (I'm not sure which, which is part of the problem) that I can simply import into any projects's src that I am working on--kind of like my own, one-class, library. While trying to figure out how to do this, I came across the two following blog posts--
http://blog.jetbrains.com/idea/2011/10/new-in-11-create-library-from-project-view/
http://blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/
--but when I tried to do what they instructed (creating artifacts in Project structure, etc.) I wasn't able to because my class doesn't have a main() method, as its not meant to. So I was wondering if I was going about this right--is there a way to do this, or am I stuck with copying and pasting?
I managed to get it--I had to go into Project Structure and set it to create a jar file containing my compiled .class file upon build. Then I could add the jar file as an external library in my other projects. Thanks guys for the replies.
You only need a main method if you want the package to be able to run as a standalone application.
So, to answer your question: no.
You don't need a main method to create a package, nor to import or use the package/library in a separate application.
I've already asked about some similar things connected with theme above and google a lot, but I still can't find exactly what I want, so here we go:
I want to make library, which will use other libraries. I mean some of javacv's .jar's, which we can find here: javacv site
. Some of these libraries are 'normal', some of them contains .dll's. I want to create independent .jar file, which could be use together with above .jars in different projects. Classes in this my .jar file will use methods from javacv's .jars. So my 'independent' library will depend on javacv.
In parallel, I'd like to write application, which will use javacv and my library. So I'd like to create 2 projects:
A) Library, which will depend on javacv 's jar's (I should get here .jar, which could be use in other projects together with javacv)
B) Application which will depend on library from A) and javacv's jars
What should I do in Netbeans (or eventually in Eclipse) to organize it in best way? I know, that I probably should use maven / create some maven projects but I don't know a lot about maven ( I can add... dependency :) ).
I have been struggling for days but I could find a good way to organize packages.I have created some classes and I want to have them in every project like all the java classes but i can't. for example if i create a class and define the package like this
package myclass.importatnt.test;
this class is available only in this project. If I want to have this class in other projects I have to copy/paste the folder myclass in the other project folder and this is really boring. Is there any way to organize the packages so I can use them in any moment?
It seems you have some utility classes that you want to reuse in multiple projects.
Instead of copying the source code of the classes in every project, you should instead compile the classes, package the class files in a jar file, and add this jar file in the classpath of every project needing them.
That's what you do with every other librery that you use (commons-lang, guava, whatever...), and there's no reason not to do the same with your own utility classes.
If your using eclipse, go to Project->Properties->Java Build Path, and add your project to the list of required projects (under the Projects tab). Then you should be able to import them.
I am trying to create a java file from scratch using AST but it is painstakingly taking me longer to finish. What I have in mind is create the java file, then create the project and package and then copy that file to that package. Is there a way to do this?
Thanks.
I use Apache Velocity, in order to create Java classes from templates. In my case, i had to create from (velocity) templates some classes (and maven pom) using Eclipse Wizards. But if you want to modify these classes, then the best choice would be AST/JDT.
http://sdqweb.ipd.kit.edu/wiki/JDT_Tutorial:_Creating_Eclipse_Java_Projects_Programmatically
shows how to create a java project using JDT and configure your classpaths subsequently.
You can use JBoss forge to generate java classes problematically. it has api to write scaffolding plugins. it uses Apache Velocity templates to do that.
Also Spring Roo can be another choice, if you are a Spring guy ;)
IFile#setContents(InputStream ...) would seem like a good candidate.
You can also use the ImportOperation to import files from anywhere (incl. the filesystem outside of the workspace) into a project.
As I do more and more coding in Java I am creating a library of methods that I use often. Is there a way in Eclipse to set it so that I can import these methods from the source folder of the library project to other projects without copying them to each individual project?
I know there is something that I can do with the Build Path, but when I try to add the source for my library I get a package error in the project it is linked to.
Thanks
Don't import/copy the code from another project--the point is to use the output of the shared project. Just indicate that the project depends on the other project; don't think about the shared project's source.