Netbeans/Java: reference a jar but not deploy it - netbeans

I want to build a jar containing a class which I have derived from a class in second jar. I add a reference to the second jar in my project but then Netbeans copies that jar to dist/lib which I don't really want. Is there a way to reference the second jar at compile time but not have it copied.
Specifically, I am making a custom task for Ant so I derive from org.apache.tools.ant.Task and I don't want ant.jar copied to dist/lib.
This is with Netbeans 7.0.

One way of achieving this is to 'Uncheck' the Copy Dependent Libraries check box, which will ensure that no JAR files are copied to dist folder.
Exact Steps:
Right click on the project name and choose Properties option from the context menu, this will open the Project Properties dialog box.
Select the Build > Packaging node from the Categories tree view and uncheck the Copy Dependent Libraries check box
Now build the project and check that no JAR files for libraries are copied to dist folder.

Related

Netbeans to Eclipse migration for Java Projects

I currently switched to eclipse and trying to migrate my projects. I created a java-workspace and used 'File->Open Projects from File System'.
The project with all the folders is added, not only the 'src' but everything I put into it (datasheets, documentation,...). Also the libraries are added two times. One time in the folder and what seems like a link to the compiled library.
folder structure
In netbeans I just added the desired library to the /libs folder and linked it to the project.
Can I manually add folders and/ or libraries to existing projects? Why are there two instances of the libraries?
By using Open Projects from File System, folders containing .java files has been configured as source folders (source code intended to be compiled). This can be undone via right-click Build Path > Remove from Build Path (the reverse function is Build Path > Use as Source Folder).
In the Package Explorer, source folders are shown as virtual folders. If the source folder is not a subfolder of the project, it is displayed as virtual folder in addition to the project subfolder to be able to navigate to that non-source project subfolder (in your case you have a single src source folder and in addition to the non-source folder lib you have multiple virtual lib/... source folders).
The node Referenced Libraries lists all JARs and class folders on the Java Build Path (classpath/modulepath). To remove something from the Build Path, right-click it and choose Build Path > Remove from Build Path. JARs can be added to the Build Path by right-clicking the JAR and choosing Build Path > Add to Build Path. Class folders can be added only via Project > Properties: Java Build Path in the tab Libraries with the button Add Class Folder....
I dont know if this is a workaround or good practice for migration:
Create a new Java-Project in Eclipse
add desired Folder structure (including /libs)
In 'Project->Properties -- Libraries' add libraries manually
Clean and Build Project
I have to test functionality and stability but it seems ok.

class test in an existing project j2ee converted to maven project

I'm a beginner in Maven and i have to "mavenize" an existing project for a company.
I opened the project in Eclipse and right click on the project -> Configure -> Convert to Maven Project.
So after that I didn't get the folders : src/main/java, src/main/resources, src/test/java, src/test/resources. I didn't get anything.
I have the m2e plugin and also Maven 3.3.3
I get the lib and Maven Dependency and arrange the pom.xml but i didn't have any test folder and any class Test so when running mvn:test i get no tests to run.
My question is : I have to create all the classTest manually ? Or Maven is supposed to create them automatically ?
Convert to Maven would normally:
configure the Maven Compile Plugin according to the JDK version in use by the original project
configure the build/sourceDirectory element (normally to src) instead of the standard src/main/java
ignore the bin folder used by default by Eclipse (so may see it in the Package Explorer and you can safely delete it)
Some manual steps are required (and suggested):
move the code to a newly created src/main/java folder and remove the build/sourceDirectory customization
remove the bin directory (it will now be target/classes)
Create src/main/resources folder and move any required resource (configuration file, etc.) to this folder
place your test sources under src/test/java, which you also need to create
if not the case, rename any test class to end by the *Test or *TestCase suffix so that by default the Maven Surefire Plugin will pick them up automatically (if not possible, alternatively you would need to configure it as described via official documentation here
If you don't have any test class yet, of course Maven would never create them automatically, you are responsible of writing your test cases, Maven would only run them.

Eclipse export runnable jar configuration

I am using the eclipse option to export a runnable jar from a project that I am editing. ( I have created some additional functionality through a plugin).
The runnable jar file works fine, except that is does not load the plugin I have created.
So ,I assume that I have to inform somehow eclipse to include the files I have created.
In other words,(forgive if I am asking something simple or obvious) how eclipse knows about the dependencies and all that staff ?
Since the project contained already an ant file for building and compiling ,I am wondering if this is what I have to tune.
Eclipse does not use the build.xml file to export jars. The dependencies information is kept in the .project file.
You can add your plugin as follows:
Right-click your project and select properties, then go to "Java Build Path" and select the "Libraries" tab. Add your jar here to get eclipse to recognize it as part of the project. Next go to the "Order and Export" tab. Select your jar-file here so it gets exported with the runnable jar.
When you build the jar file, make sure to select "Package required libraries into generated JAR" rather than "Extract required libraries into generated JAR". Unfortunately, I can't guarantee this will work. It sounds like rapidminer loads plugins by searching the libs directory. I don't know if it will be smart enough to recognize when it's running from a jar file and look inside the jar file it's running from rather than in the working directory.
If not, you'll have to ask your question to someone who knows about rapidminer.

Maven in eclipse not showing all folders

I am new to Maven and have been trying to get a project working with Eclipse, hibernate,Maven and mysql. I am stuck at the very first step. I have everything configured properly i think and if i create a new Maven project in eclipse it does not show me any folder under src/main or src/test. although if i go back to that folder in the workspace it has a src/main/java
FUrthermore the src/main/resources folder is not created at the time of project creation?
Any clue what the problem maybe or how i can fix it?
Thank you!
For your first problem, when you create a new Maven project the folders that get created depend on the archetype you choose. Assuming you chose quickstart, then it does create (assuming you chose com.example as your package in the wizard and example-project as your artifactId):
And it configures the project so that /src/main/java is in the Build Path. That said, if you are viewing your project in the Package Explorer view, then the packages are shown outside of the folder structure. So, you would see the the com.example.example_project package containing App.java in the build folder /src/main/java and you would see the com.example.example_project package containing AppTest.java in the build folder /src/test/java. These would show up above the libraries which is above non-build folders which is where you see the src folder.
To answer your second question, no, /src/main/resources is not generated assuming you chose the quickstart archetype (this is governed by the quickstart archetype and does the same thing whether generated in eclipse or on the command line).
And third, to fix this (I assume you mean add the resources folder), find the src/java folder (below the libraries), right click and choose New->Folder. Name it resources. Then right click your project, choose Maven->Update Project. This will cause maven eclipse to reconfigure the project according to the Maven configuration which will result in the /src/main/resources being added to the build path. As such, it will get moved above the libraries next to /src/main/java and /src/test/java.

Using java library in eclipse

I'm a bit new to eclipse and want to use the following libraries so that I can use their implemented objects (HttpClient and Java csv). How do I import these libraries so that I can write some java with them?
http://hc.apache.org/downloads.cgi
http://sourceforge.net/projects/javacsv/
What you're looking to do is add the libraries to your project's build path (the class path that will be used while compiling). In Eclipse, you can do this by right-clicking your project and choosing Properties (or hitting [Alt]+[Enter] when the project is selected in Project Explorer, Navigator or Package Explorer views) and then Java Build Path from the sidebar and the Libraries tab where you can add JARs.
Note the difference between Add JARs and External JARs is that External JARs will add an external dependency in your project since the absolute path to the JAR on your filesystem will be put into your project's configuration. With Add JARs you can select JARs from within your workspace.
I find it to be a good practice to create a lib folder (at the same level as my src folder) and put all my JARs in there and then add them to the build path with the Add JARs option. This makes the project portable since there are only relative paths referring to resources within the project rather than absolute paths or resources from other workspace projects.
You add the .jar files you want to use in your projects build path. You access this windows by right-clicking your project. Choosing "Build path" -> "Configure build path".