I have a Web Project with two source folders in Eclipse. Folder A, depends on Folder B being compiled. Is there a way to create this dependency in Eclipse, without having to create separate projects for each folder? I know projects can be set up to depend on one another, but I am not looking to do that.
The eclipse compiler automatically manages dependencies at the source level within all source folders of a project, you don't have to do anything special.
Edit: You answer "you would not be able to have Folder B reference classes in Folder A" to a comment - that's kinda the opposite of a dependency. And no, I'm pretty sure you cannot enforce that within a single eclipse project.
You can create a ant task to do that for you
You can have two programs in the same Eclipse project, with two separate main methods. You can then make two separate Run Configurations.
Before running you can then build the project. Building the project will automatically build both programs in the project, so you wont have to remember to manually build your second program.
Related
I have two projects (let say project A and project B) the two works with Spring( The same version)the only difference is that the first one has an Eclipse IDE and the second one STS and I want to use and work with the project A in the project B.
I've tried to manually copy/past a number of classes but the classes are so much dependent between them it makes it impossible.
I expect to show me how to import/export project A and use it in project B
Basically project A should be in your build path. Any of the two ways works
Export your project A as jar and add the jar to your Project B's build path.
Projects BuildPath > Projects > Add your project A.
Basically the one above me is really close , but If you will export project A to jar it might be not work if you want use it on server (Tomcat for example).
So you can make it "Runnable jar" from the first place and then as he said :
project B (right click) >>>> build path >>>> configuration path >>> libraries >>> add external jar >> and browser when you saved the jar.
now you can make instance of projects A classes and the functions already inheritance .
glad it helps you :)
I have a Java project that depends on a 3-rd party component. This component is available both as a jar and as a Maven/Ant project. One option for me is to simply add the jar as a library. However, I prefer to add the source code into my project since I may need to slightly modify their source code to better suit my needs.
What's the right way to do it in Eclipse?
My main project has a simple structure: src/ and lib/. The external component also has a standard structure: src/, test/, build/, target/, pom.xml, build.xml. So do I need to copy piece by piece (like contents of one src/ into the other src/), in which case what goes where? Or do I somehow copy it all at once? Or smth else?
The best way would be if you use maven on your projet for dependency management. This way, if you have the other projects open in eclipse, your project will resolve them as local projects, but if you don't, maven will try to fetch the jars from the configured nexus repository.
This way, you avoid having to manually configure your Eclipse projects. Maven will be able to configure your project anywhere you want to build it, not having to manually configure dependency resolution.
Import both the projects into eclipse. Add the reference of 3pp jar project to your project as a reference by clicking on Add on build path option. While delivering it as output there will be a dependency to the 3pp jar project. So either deliver it as separate jar and add it to classpath while executing your project else you have to copy the entire source files into your project and deliver it test complete jar.
Making a jar will be handled by eclipse itself.
Sorry, I'm very new to java servlets. I have an existing java package (that I built and ran in eclipse, did not compile) that runs fine on its own. I have a sample servlet in another folder. I'd like to compile all of this so it can run on a tomcat server. I know a javac will compile a class, but which one do I compile if this is a servlet AND another package? Do I have to list ALL classes, can I list just the package names? Do I need to create a single .war file or multiple .war/.jar files?
Sorry, my use of Java up to now has been in Eclipse. I can compile and run a single class, but a complex environment with multiple packages with a target platform of tomcat is leaving me lost as to 'where I begin.
You can do following:
1) First project should be able to create a jar file.
2) In the Second project ( Servlet) ,you can right click on the folder of the dynamic web project( I assume you have created it as DWP) , and click Properties --> Deployment assembly. Here you can add reference to other projects and external jars.
3) Once you are able to do this setup, you can try 'exporting' your second project as war.
This is just a naive way to start as I do not want you to overwhelm with complexity of multi module development for a beginner. But will point you to m2e plugin in eclipse for something called "Dependency Management" . This plugin will help you manage much more bigger and complex projects. Do spend some time on http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/ to understand maven and how to it works before attempting Maven in eclipse with m2e plugin.
I've seen different packages in source code such as com.website.package These packages are used across multiple applications, and I've been trying to accomplish something similar.
The only way I know of to achieve using the same packages in different projects is to copy each source file into the new project which would create the new packages. this probably isn't the preferred method, as it could possibly drag thousands of files into the project (see Java's library).
How would this be achieved?
TL;DR: How can I use a custom written package in multiple projects without copying many files? (aka Java's libraries).
Take the class files and create a jar. Put the jar on the classpath of all the applications that need those classes.
How do you do that?
Inside an IDE, you can create multiple projects and put the shared java code in one project. Make the other projects depend on that project and you can share things within the IDE. That means you run inside the IDE and it will use the shared code.
For example, in Eclipse, you choose the project that will use the shared code/project. Right click on it in the package view or navigator view and choose "properties". Select the option to set the build path and there is a tab for selecting projects that this project depends on. Select the shared project and then it's code is callable from that project.
In this case, any change you make to the shared project will be immediately available, inside the IDE, to those projects that depend on it. Run them right then and the change will be in effect.
For running outside the IDE ...
If you are using Eclipse (or some other IDE) it will have an option for creating a jar. In Eclipse you create a java project and move the classes you want to be in the library/jar into this project. Then, once you have all the right classes, including those that others depend on, you will do some sort of build to create the jar.
Eclipse has an 'export' option on the 'file' menu. Use that and select to export as a "java" > "jar" and then select the project you just made.
You can also create a Maven project of type "jar" into which you put all those classes (as java files) and then building that project with Maven will create the jar. The "install" goal for Maven will deploy it to your local repository.
Any time your shared code is shared by way of a jar, you will have to rebuild the jar and copy it into the location(s) from which it is shared by other projects before changes inside the jar take effect.
Maybe export the package to some place on the drive and create linked folders to it in the projects?
I am working on a Hadoop project in Eclipse that depends on another one of my projects; I've included the other project in my build path, but when I export the dependent project, it only contains the classes from that same project.
Ordinarily, this would not be a problem, as I could just link the other project with the -cp flag, but Hadoop requires you to pass the jar as an argument, meaning that all of my dependencies must be inside that jar.
Is there a way, in Eclipse, to automatically build and include classes from projects that you depend on?
Thanks.
You coud use Ant to automatically build, test and export. It needs some time learning it, but its worth.
There are possible tasks (fileset, zipgroupfileset, copy) to include files, jars (unzipped) or anything into the final jar. By this way you definitly know whats inside your distribution jar and you don't need an eclipe installation running.
I suggest you take a look at maven as a build tool. You define the dependencies and build steps for each of your projects in files called pom files. The maven plugins for Eclipse (the m2e plugins) can take the configuration in the pom file and setup your Eclipse build paths and project description so that you can access the classes in your other project in Eclipse. Maven can also create a jar for you that has the classes from both projects (a "jar-with-dependencies").
In maven terms, your two projects are called "artifacts" with one having a dependency on the other.
The one downside to maven (and the cause for many negative comments about maven) is an initially steep learning curve that can be frustrating. What you're trying to do, however, is very straightforward and I expect you can find a number of examples showing you exactly what you want to do.
The first step, and that's what my answer is about, is to take a look at maven. It may seem overly complex, but it can scale to handle just about any build configuration you need as your hadoop apps get more and more complex.
You can export a project as a Runnable jar, which can be useful if you want a single jar, with dependencies included.
Select the Project. File > Export. Select the Java section. Select Runnable JAR file.
See related answer:
Eclipse: How to build an executable jar with external jar?