Trouble making executable jar - java

When I try to make an executable jar in netbeans I get this error
C:\lwjgl\lwjgl-2.8.5\res is a directory or can't be read. Not copying the libraries. Not copying the libraries.The res folder holds files like jpgs and wavs that the program relies on to function. I'm using lwjgl, would that be part of the problem? What could be causing this?

try this
Right click on your project folder and click on >>>>clean and
build<<<<
right click on your project folder click on >>>Properties<<<< you
should see the location of your project folder normally this should
be in your documents folder under NetbeansProject folder. locate
your project name folder inside is a folder called >>>dist<<< in
there you should find your project name with a small java cafe
image which is your jar file.

Related

How to include some folder in target but not in out folder in IntelliJ IDEA

Surely there will be an answer to my question but I've been trying for days and I can't in any way.
This in the picture is the structure of my target folder. I would like to make the folders: image and video not be placed in the .jar file once the file is built but be placed as external folders in the same location as the .jar file.
However, I would like the folders to remain in the target file to allow me to access them via class.getResource during the test phase but once I have obtained the .jar file I have to be able to change these images at will and I don't want them to be present inside the .jar.
I hope I made myself clear.
I tried something inside the project structure but with no result
Structure folder

How to include resource folder in executable .jar file in eclipse?

I need to create an application for sorting various types of polygons using various parameters such as height, volume or base area. Arguments for Filename which has parameters for polygons, Sort type, Sort method will be pass through command line.That file is in my resource folder outside my src folder in a project. I have implemented all programs, It works fine when I run using pass arguments through eclipse run configuration. But when I try to run my .jar file using cmd same arguments it gives me FileNotFoundException.
I opened my jar file using 7zip and noticed it never extracted my resource folder in .jar file. I searched online and tried including my resource folder in to build path of eclipse. But still does't work.
Follow these steps:
1) click project -> properties -> Build Path -> Source -> Add Folder and select resources folder.
2) create your JAR!
EDIT: you can make sure your JAR contains folder by inspecting it using 7zip.
Reefer this link as well How do I add a resources folder to my Java project in Eclipse
First, you need to create a source folder for resources, for instance name it res, and then move your image folder to res. When you generate the jar file, you will see the image folder, not the res folder or files separately.
This comes down to how you are generating the JAR file.
When you're exporting the jar in eclipse make sure to checkbox the button that says "Export java sources and resources" https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/ensureJavaFiles.jpg
There are a lot of ways to do this one is to use Gradle is the recommended way, something like this will work Creating runnable JAR with Gradle

Eclipse is asking for a jarfile from a folder that I no longer have

I did some school work on a school PC and I added a file to my eclipse library
that existed in a folder path from the school PC.
When I got home all of my projects have folder path errors on them and when I
tried to download that file again and add it to my eclipse library it doesn't
count it and still asks for the that exact same file but from the school PC
folder path.
I don't know what to do because I can't just remove it.
Adding it as an external file doesn't solve the problem because it still asks for that file from the school folder path.
e.g.:
As you can see in the first image it doesn't let me remove the jar file or edit it.
In the second picture you can see how all of my projects have errors due to this missing file. You can also see how I tried to add it as an external jar and it didn't recognize it
Make sure that the .classpath file inside the imported project is not hidden. If it is hidden then unhide it and then try again to delete the jars you don't want.

Android Using Jar Files

So I'm trying to use the jReddit wrapper class because I am developing a reddit app on the android. Here is what I did:
I first went to jreddit and downloaded as a zip
Then I went to eclipse, made a project and copied the files from the extracted folder into the new project. Here's a picture of what it looks like:
Then I used the build.xml from here and "Ran as Ant" to create a jar file in the dist folder as you can see above
I made my android project and copied the jar file into the lib folder and built the path. The project looks like this:
Finally, here is my MainActivity.java. Sorry, I couldn't format the code properly on here
There are no errors, so I can run it on the android. However, when I click the login button to activate the function call onClickBtn, before it can even get into the function it throws an error saying: Could not find class 'im.goel.jreddit.user.User', referenced from method com.example.reddit.MainActivity.onClickBtn
Did I not import this jar in correctly or am i just not using it properly? Why is it compiling fine like it can see the user class but when run on the android it doesn't know what it is?
Extract the contents to the same folder as your other classes. Usually src.
Or
Go to project properties (Alt + Enter) and select Java Build Path (Left panel). Then select Libraries (Top middle). Click the Add External JARs button and select your jar.

How to create a project from existing source in Eclipse and then find it?

I have created several .java files. All of them are located in one directory. I used a text editor to write these files. Now I want to switch to Eclipse. How can I do it? I have tried many ways. None of them works.
ADDED:
I think the common way is to have source in the eclipse folder called "workspace". So, how do I get my files in these directory. Should I use eclipse to create a new project from existing source and Eclipse will put all file to the workspace? Or I should manually copy all my files to the workspace? Where should I put my class files than? Should I create a subdirectory? With which name?
ADDED 2:
When I try to create a project with name "game", the eclipse writes me that a project with such name already exist. But how can I open this project?
ADDED 3:
In my "workspace" I have created a subdirectory called "game". I copied all my .java file into this subdirectory. Then with Eclipse I created a new project with the name game. As a result, Eclipse created .classpath and .project files in the directory "game". It also created bin and src subdirectories. And now I think it is not the correct way to go. The source files are supposed to be in the "src" directory. Right? And at the moment all my .java files are in the "workspace\game".
ADDED 4:
I did it other way around. With Eclipse I have created a new project with the name "game". As the result, Eclipse created a folder called "game" into folder "workspace". In "game" the folder I found "src" folder. I copied all my .java files into this folder. But now in the "Package Explorer" I cannot open "src" folder. So, how can I access my source files from Eclipse? Why Eclipse does not want to open the "src" folder?
Easiest Method:
Put all source files into one directory named after your project. i.e. "ProjectName" You can keep this directory in your workspace or it can be somewhere else.
Start a new project in eclipse and name it using that same project name.
Uncheck the "use default location" box and find the directory where your project is unless your project is already in the workspace - then you must not uncheck the "use default location" box
Click 'next'.
Eclipse should be smart enough to figure out what's going on. After clicking next, it will show you all of the files it found in that directory. It will just automatically add those files to your project. VoilĂ !
Right-click in the package explorer and select New - Java Project
Create the new project Game
Open the new project in the package explorer - you should see only the source folder called src (there's nothing inside yet)
Open a file Explorer (e.g. Windows Explorer) and drag your sources
Drag them to Eclipse and drop them inside the new src folder - if asked select "Copy files"
Eclipse should put the files into the default package, if that's not correct you can edit the offending files (marked with a red cross) by opening them in Eclipse, selecting the package declaration (usually line 1), pressing Ctrl + 1 and selecting the appropriate option (e.g. "Move xy to package com.game"
This answer is going to be for the question
How to create a new eclipse project and add a folder or a new package into the project,
or how to build a new project for existing java files.
Create a new project from the menu
File->New-> Java Project
If you are going to add a new pakcage, then create the same package name here by
File->New-> Package
Click the name of the package in project navigator, and right click, and import...
Import->General->File system (choose your file or package)
this worked for me I hope it helps others.
Thank you.
The easiest method is really good but you don't get a standard Java project, i.e., the .java and .class files separated in different folders.
To get this very easily:
Create a folder called "ProjectName" on the workspace of Eclipse.
Copy or move your folder with the .java files to the "ProjectName" folder.
Create a new Java Project called "ProjectName" (with the Use default location marked).
Press <Enter> and that's it.
There are two things
1- If its already a Eclipse Project, then simply go to File->Import->General->Existing Project into Workplace
2- Otherwise define project type e.g. Java, Web etc
Create a new project of type you define into your workplace. Copy Paste source , lib and other necessary files. refresh, compile and run project in eclipse.
In the package explorer and the navigation screen you should now see the project you created. Note that eclipse will not copy your files, it will just allow you to use the existing source and edit it from eclipse.
There are several ways to add files to an existing Java project in Eclipse. So lets assume you have already created the Java project in Eclipse (e.g. using File -> New -> Project... - and select Java project).
To get Java files into the new project you can do any of the following. Note that there are other ways as well. The sequence is my preference.
Drag the files into the Navigator view directly from the native file manager. You must create any needed Java packages first. This method is best for a few files in an existing Java package.
Use File -> Import... - select File System. Here you can then select exactly which files to import into the new project and in which Java package to put them. This is extremely handy if you want to import many files or there are multiple Java packages.
Copy the fires directly to the folder/directory in the workspace and then use File -> Refresh to refresh the Eclipse view of the native system. Remember to select the new project before the refresh.
The last one is what you did - minus the refresh...
While creating a project from a full folder may or may not work within the workspace, there's a condition outside of the workspace that prevents starting a new project with a full folder.
This is relevant if you use numerous folder locations for sources, for example an htdocs or www folder for web projects, and a different location for desktop Java applications.
The condition mentioned occurs when Eclipse is told to create a new project, and given a full folder outside the workspace. Eclipse will say the folder isn't empty, and prevent creating a new project within the given folder. I haven't found a way around this, and any solution requires extra steps.
My favorite solution is as follows
Rename the full folder with an appended "Original" or "Backup.
Create the Eclipse project with the name of the full folder before the folder was renamed.
Copy all the relabeled full folders contents into the new project folder.
Eclipse should make a new project, and update that project with the new folder contents as it scans for changes. The existing sources are now part of the new project.
Although you had to perform three extra steps, you now have a backup with the original sources available, and are also able to use a copy of them in an existing project. If storage space is a concern, simply move/cut the source rather than fully copy the original folder contents.
If you creating a new project based on an existing Maven structure :
Create the project using a general project wizard and give the project the same name as just created.
If you try to create the project as a Maven project via m2e will receive an error that project/pom already exists.
Create a new project..
Right Click on your project..
Select Build path --> Configure Build Path
Under source tab choose link source, your .java files containing folder..
I am suggesting this since none of the methods that you tried have worked ---FYI
Follow this instructions from standard eclipse docs.
From the main menu bar, select command link File > Import.... The Import wizard opens.
Select General > Existing Project into Workspace and click Next.
Choose either Select root directory or Select archive file and click the associated Browse to locate the directory or file containing the projects.
Under Projects select the project or projects which you would like to import.
Click Finish to start the import.

Categories