Netbeans not building the lib folder in the dist folder - java

I am trying to clean and build a jar but for some reason when I do a Run-> Clean and Build Main Project, I don't get a lib folder in the dist folder. This is causing a missing classes error when I run my jar file via cmd. How do I configure it to have the lib folder in my dist folder during my build? Thank you.
Edit:
Also, when I hit Run->Clean and Build Main Project, the output says the following:
2 warnings compile: Created dir: C:\Documents and
Settings\me\Desktop\ProjectX\ProjectX\dist C:\Documents and
Settings\me\Desktop\ProjectX\ProjectX\dist\ProjectX.jar is a directory
or can't be read. Not copying the libraries. Not copying the
libraries. Building jar: C:\Documents and
Settings\me\Desktop\ProjectX\ProjectX\dist\ProjectX.jar To run this
application from the command line without Ant, try: java -jar
"C:\Documents and
Settings\me\Desktop\ProjectX\ProjectX\dist\ProjectX.jar" jar: BUILD
SUCCESSFUL (total time: 3 seconds)
Why is it not copying the libraries during the build?

According to this forum.netbeans.org (cached copy as forums.netbeans.org is not accessible atm) article this could be caused by ProjectX.jar being added to the required JARs for some mysterious reason... Could be worth checking
EDIT: cached copy seems to have disappeared, the original thread can be found here.
EDIT again: as both the original and the cached copy have disappeared, head over to the wayback machine to read the article. That being said, anno 2018+ one should probably consider using a more modern / widespread project format like Maven, which is also well supported by Netbeans and offers a much more flexible libraries management approach.

In my case I went to Libraries->Properties. The "lib" folder was added as a library. remove it or remove them (several folders as libraries) and do clean and build.
Hope help you.

The url provided by #fvu die.
However I also have that problem and fixed it.
Exit Netbean
Delete your-project-name/nbproject/private
Open Netbean
Clean and build

In my case, I solved the same problem as follows :
1) Go to Project > Libraries > Properties > Libraries > Compile
2) Select missing libraries beginning 'Missing library :' and remove them
3) Clean and build
Cheers.

The problem is that you add the folder where are you libraries, you need to actually add the libraries and not the folder where they are.
1) Go to Project > Libraries > Properties > Libraries > Compile
delete the folder you add in these case C:\Documents and Settings\me\Desktop\ProjectX\ProjectX\dist
Select add JAR/Folder and these time open the folder and add all the libraries inside, Netbeans will allow you to select it all.
Now you suppose to be good.

There is a setting in Net Beans. Right click on Net Beans project you have created.
Click on Build->Packaging. You will get 03 options on the right pane
Compress JAR File
Build JAR after Compiling
Copy Dependent Libraries
Select the 03rd one and then build. You can see the /lib folder under /dist

Related

eclipse doesn't compile the project

I had running project opened in eclipse. After an accidental restart of windows, now when I open the eclipse I see my project is marked with a little red cross. Now when I run the main method I get a java.lang.NoClassDefFoundError.
I have tried restarting eclipse, Project -> Clean but it doesn't solve the problem.
When I checked the project directory, inside 'target' folder there are no compiled .class files. I tried building the project but I can't get the compiled class files, which is the reason for the error.
How do I solve this?
I tried all the solutions here, but here's what worked for me.
First, remove the project from eclipse.
Then, in your project folder, delete the 2 files that eclipse creates. They're hidden, but they're called .project and .classpath.
Finally, add the project back into eclipse and eclipse will recreate those 2 files and a new configuration for your project.
My specific issue was that it a project that was missing a Java Builder because it thought it was a scala project. The only way for me to reset this was by removing the project, deleting the 2 files, and adding it back in.
Maybe Eclipse's workspace files have become corrupted. Restart Eclipse and choose a new workspace folder (or choose Switch workspace from the menu). Then import the project files into a new project.
Try deleting the run configuration and remaking.
If that doesn't work, open the class, ctrl+f11 to run. That will force Eclipse to update its classpaths & rebuild its main indexes.
To delete the configuration:
- Menu -> Run -> Run Configurations.
- Select your configuration
- Press delete or use the delete icon
If you are using maven, this will likely fix it: Right click your project -> Maven -> Update project.. (or alt + F5), select your project, make sure "Refresh workspace resources from local filesystem" is checked and click ok.
My eclipse project has similar issue though the error appeared slightly different. I imported a third party java project into Eclipse, with Project > Build Automatically checked, do a Project > Clean..., no classes were generated in the output bin folder. Tried different options, no luck.
I noticed a red exclamation mark at the top left corner of the project name.
Right click on project name, Properties > Java Build path, I saw "Build path entry is missing: cci/src". Manually created src folder, the red exclamation mark gone. Do a Project > clean..., project compilation successful
P.S. The eclipse project is not properly organized, there are no code under src folder. I suspected src folder went missing while checked in by original author since there are no code there.
Was having the same problem and finally found the glorious hint here.
In my project there is one *.scala File and Eclipse Neon is incompatible with the Scala IDE, thus there is no builder for scala and the whole project is not built.
After removing the Scala file and the Scala Package from the linked Libraries )Project Properties --> Build Path --> Libraries) and afterward re-adding the Java Builder (no idea why this one went missing, but here's a useful help on how to add the Java builder when missing), the project could be built and run again.
Try refreshing and then cleaning the project.
For me the problem is in missing jars,the jars were added first and the location of those jars where changed after.
So When I correctly added all the required jars again to the build path, it starts to build project correctly.

Eclipse does not recognize org.jdesktop.*

I use JRE system Library [jre7] and when I import org.jdesktop.application.Action I get
The import org.jdesktop cannot be resolved
I removed the build path by Build Path > remove from build path and then I did
project > properties > java build path > add Library > JRE system Library and still same error .
If anyone is interested, I had to download 3 JARs:
appframework-1.0.3.jar (link in previous post) wich contains org.jdesktop.application classes,
swing-layout-1.0.3.jar link wich contains org.jdesktop.layout classes,
swing-worker-1.1.jar link wich contains org.jdesktop.swingworker classes, required by the others jar
The org.jdesktop code is not part of Java SE, so the classes won't be in the JRE. You need to locate and download a JAR file containing the classes, and then add it to your Eclipse buildpath.
(One place to download the JAR is here ... but it is easy to do your own searching if this link breaks. Go to Maven Central or findjar.)
Just download the corresponding jar file from here . And you are good to go.
Add the jar to your build path.

How to Build "Thinking in Java" Example Files to Run in Eclipse IDE?

I wanted to learn Java, as recommended by most of the people I downloaded "Thinking in Java" eBook and Source Code Example Lesson files from mindviewinc.com it's download location is this http://www.mindviewinc.com/TIJ4/CodeInstructions.html
These files don't work with Eclipse IDE for some reasons. So we have to build the files using the Build.xml file included in it's source code (Honestly, I do not have any idea what does "build" means here)
I tried building myself but of no use.. It did started building but after reaching some folder it stopped and gave error to install jboss-osgi-installer-1.0.0.jar .. After downloading it, I had no idea what to do with it, so I double clicked it and it asked me the location to install and I installed it in the default location, which was C:\Users\Username/jboss-osgi-1.0.0 and when I tried C:\Program Files\Java** the installation gave error that "this directory cannot be written, please choose another directory!" but anyway I installed it in the default location and it installed..
and again when I tried to build it, it gave me the same error and asked to Install Jboss....... I'm stuck.. This is happening again and again, wasted many days and didn't even crossed 100 pages of it's pdf because of this reason. It's a good eBook though.
I'm stuck in this from months... Please some one build it and make it like a project which could be easily and send me the project file, it would be really appreciated as I can not the solution to this anywhere on search engines..
Ok here's what I did to succesfully import the sources found in the "accesss" folder of you code samples:
Download the javassist jar as per Bruce's instructions, from here:
http://repo2.maven.org/maven2/javassist/javassist/3.9.0.GA/javassist-3.9.0.GA.jar
You must create an Eclipse project for the sources that are used as dependencies for most of the examples, that's the sources in the "net" folder:
in eclipse make new java project.
select the "net" directory, copy it, then in eclipse select the "src" entry in the project you just made, right click on it and select paste.
after eclipse finishes and auto-builds, it will complain about the missing javaassist jar. Right click on the project ->properties->java build path (on the left)->libraries (on the top)-> add external jars... (on the right), browse and select the javassist jar from where you down load it.
now the "net" project should be ok in eclipse
Now let's create the project for the sources in the "access" folder:
create a new java project in eclipse
Now, because Bruce structured his classes like crap, we'll have to make the proper structure in eclipse for them. This means:
a.create a new package called "access"
go to where your the access folder is on your drive, open it, select ONLY the folders (cookie2, desser, mypackage), copy them, then return to eclipse, right click on the "access" package u just made and click paste
now go back to the access dir on your drive, select ONLY the .java files (all of them, not the dirs), copy them, the back to eclipse, click on the src entry in the access project and click paste.
The access project in elcipse will still complain about missing classes form the "net" resouce. Right click on the project in eclipse->properties->java build path->projects (on the top)-> add(on the right)-> check the net project you created earlier-> click ok twice.
Now it should be ok
I hope you got the idea on how dependencies work in eclipse with this example.
For the other parts of you code samples, create separate java projects, add the classes to the proper package (create the packages if Bruce forgot to), and if you are missing external jars, go to http://search.maven.org search and download the jars. Good luck
"This code is designed to work outside of IDEs. Because packages are not introduced until later chapters, and some of the fancier IDEs like Eclipse require all code to be in packages, if you want to use the code inside those IDEs you will have to make some adjustments" - yep, bruce eckel would say that, cause that's the kind of guy he is. He also said there's ONLY checked exceptions in java, and asked for unchecked exeptions to be added as a bonus.
Now, if your sample code has no package, aka it's in the default package, aka when you look in the .java file, right at the top there's no line saying "package what.ever.bla" then all you have to do is:
-in Eclipse create a new Java se project
- open a windows explorer, go to your .java files, select them and copy them
- then in eclipse, right click the src folder in your project and chose "paste"
The files should be added to a "default" package in your eclipse project, without any error
Here is the simplest steps that I find to create a clean Eclipse project for the TIJ4 source code:
Download the source code zip from: http://www.mindviewinc.com/TIJ4/CodeInstructions.html, and unzip it to a folder, say 'TIJ4-code';
Download the additional libraries as in the previous URL, copy tools.jar from your current JDK's lib directory, and put them into TIJ4-code/lib;
Go into the 'TIJ4-code' folder, and run 'python Eclipse.py' (you need python installed on your system). This script adds the missing "package xxx" line to those source java files which don't yet have them, so as to make Eclipse happy. It also generates the Eclipse project files, which doesn't work well for some reason (beyond my limited knowledge on Eclipse), but they aren't needed here;
Open Eclipse and create a new empty java project, say with name 'TIJ4', choose JRE version 1.5, and "create separate folders for sources and class files";
Copy TIJ4-code/lib directory to your new Eclipse project folder;
Right click on the new project and select "Build Path" >> "Configure Build Path", then go to tab "Libraries", "add jars", then select all the jars under your project's lib folder;
Go to "File >> import", choose "General >> File System", select the unzipped folder 'TIJ4-code' as your "From directory". Check the root 'TIJ4-code' in the left panel of the import window, Click on "filter types" and select the .java, so that unnecessary files of other extensions, like *.class, *.py, *.xml, etc can be ignored during the import;
The zipped folder is no longer needed after the new Eclipse project is built. I hope you find this instruction helpful, and have fun learning TIJ4.
If you want to use this code in IDE rather than Eclipse and so on, for example in Intelij Idea or any other, the best way is to compile necessary classes from the TIJ4 with Ant, but it is not easy for the beginners, although it will be a good practice for you. You should make some changes in build.xml files which exists in every directory of TIJ4. Why?
to change version of Java(now we all use Java version higher than 1.5)
to include javaassist.jar library in the "classpath"
to put all compiled files in 'bin' directory(by default without adjustments TIJ4 build.xml puts .class files in the same directory with .java files. That is not a good deal.
For example you need to import and use within IDE(I use Intelij Idea) the class named net.mindview.util.Print ( see Chapter 3):
download TIJ4 and unzip in any directory you want(for example it would be c:\eckel)
download and install AntApache (you can find detailed instructions how to do it in Google) The result is - type in your console ant -version and you should see the answer. So Ant is working.
download javaassist.jar from http://jboss-javassist.github.io/javassist/ . Unzip to any directory, take out javassist.jar and past it to c:\eckel\net
4.There is build.xml file in c:\eckel\net. Now you should make adjustments. Open it with NotePad++ or other editor.
If you don't have Java 1.5 installed on your PC, so change all 'vesion1.5' to 'vesrion1.8' or other version that you have installed.
after tag description put property name = "classpath" value="./;./javassist.jar"/>
<property name = "src_util" value="./mindview/util"/>
<property name = "src_simple" value="./mindview/simple"/>
<property name = "src_atunit" value="./mindview/atunit"/>
<property name = "destdir" value="bin"/>
Then we make targets that will complile util simple or atunit automatically
Change tag available <available
classname="javassist.bytecode.ClassFile"
classpath="${classpath}"
property="javassist"
/>
Now classpath of available = property named 'classpath'. Classpath is the path where java compiler looks for .class files because some of your .java files want them by having import statement. There won't be error message "You must install the Javassist library " any more
Create targets for compiling util simple and so on See the following link with code
Code with targets
You can modify exists targets not to write all the code.
at the top of build.xml file change default="simple"
open cmd, then cd c:\eckel\net , then ant -simple or just ant (simple will run as default)
Please write if you will have some problems. Possibly i forgot mention about something.
Go to Intellij Idea, press Ctrl+Alt+Shift+S
Press +,
Library or directories
choose your c:\eckel\net\bin
5.now you can use import statement for all classes that exist in net.mindview
6.you can make the same with other dirs.
If you wish to you skip the entire Ant build process, I have converted the project to a Maven project (over JDK8), which you can simply import into your Eclipse workspace.
https://github.com/gauravojha/tij4-maven
Thanks to #Sergey Oliv's example. In addition, I needed to provide uncompiled javaassist package with all java files in the 'net' folder too. The .jar wouldn't work by itself.
I must say, this was a lot of work to get going.

spring framework download

So i downloaded Spring Jars from this link and I am trying to unzip the file, it keeps on complaining that some of the total path and file must not exceed 260 chars and it breaks from unzipping. How to download the jars and include them in my eclipse installation for working on my web projects, although this may seem trivial for some people it is very annoying to get around as i am new this kind of stuff. Really appreciate your help.
Thanks,
SS
Did you just unzip the zip file or the jar files? Just unzip the zip file, copy the jars in a lib folder in your project and add the jars to the buildpath of your project (Right click on the project -> Properties -> Java Build path -> Libraries -> Add jars).
And don't use the unzip functionality included in Windows, use an external program like 7zip. Then that error shouldn't occur.
You shouldn't need to unzip or unjar JAR files to use them in Eclipse. In fact, I'd recommend NOT doing this ... especially on Windows ... because it is liable to increase the amount of disk I/O.
But if you do want / need to do this, the jar command that is part of a Java JDK installation will be able to cope with them.
What you got was the correct ZIP . Now try to unzip it in something like c:\Spring instead of a nested folder like C:\Users\abcuser\Downloads\Spring\Spring Framework Notice the size difference between file paths.
To add jars to your eclipse project -
Right click project
Click "Build path" -> Configure Build Path... -> Libraries Tab
Click add external jar and select your jar

In Eclipse, how can I exclude some files (maybe based on the .svn extension or filename) from being copied to the output folder?

I'm developing a Java application using Eclipse. My project has two source directories that are both built and then some files are copied into the output folder. From the output directory I then run my application and all works well.
However, I keep having these warnings:
Snapshot from Problems tab in Eclipse http://www.freeimagehosting.net/uploads/128c1af93f.png
Anyone know how to get rid of these warnings? Maybe by excluding some files, maybe based on the .svn extension or filename, from the build process? If so, how would I go about excluding those?
Have you tried to add
**/.svn/
to the Exclusion patterns at the Source preferences of the project's build path settings?
You could also try installing the Subversion plugin (Subclipse) for Eclipse.
Sure, that easy:
at Project Properties -- Java Build Path you can add exclusion filters on every source folder.
There, you can add an exclusion pattern as *.svn
That sounds like your building process is using versionned directory within your subversion workspace.
Should you not have your 'output' folder and/or your 'tst' folder be made 'private' ? (that is without any .svn, and ignored by subversion)
Right click on the source file > Build Path > Exclude.

Categories

Resources