Heroku API: adding the jar into NetBeans - java

Following up on How to obtain databse url etc without the heroku CLI I have added https://github.com/heroku/heroku.jar to my NetBeans project's library: "Add JAR/Folder" (I copied the jar first to /home/username/netbeans-8.2/ide/modules/ext) But HerokuAPI is not being recognized, and Alt-Space does not show any suggestions for imports, so I guess netbeans simply has not recognized the jar's contents. Maybe this thing is hidden in the default package, and so I can't import it?
EDIT: Here is the image
So, it is in the default package after all? How to fix this?

I had to create a new -- now Maven-based -- project and resolve the dependency using pom.xml, as explained on https://github.com/heroku/heroku.jar

Related

cannot find or load main class when run a jar

Firstly, I know this problem is asked frequently. But My problem is different, so please be patient to see the full description.
I have utilized intellij IDEA 2018.2 to build the jar. I have ever built the jar with 2017 and it worked fine. Recently, I have used intellij to build the jar with artifact.
And the setting seems to be fine. It worked for me before. But I ran the built jar, it indicated that "the main class cannot be run or loaded".
The jar file seems normal. But I found the META-INF is different. I have some files are strange:
I find if I delete these files except MANIFEST.MF. It can work fine. I am not sure what's the difference of the settings.
I have tried the below methods:
Try to delete the .idea folder, and open the project.
Try to remove the artifact and configure a new one.
Try to modify the output path of module.
Rebuild the project or rebuild the artifact jar.
But all the methods cannot work. And I have tried to build the jar with the same settings in both MAC OS and windows OS in intellij, but the result seem to be same. Can any one provide me with some suggestions. Thank you in advance.
The *,RSA, *.SF, *.DSA are files that are created when the jarfile is signed. Apparently, the jars that you use are signed and so if you extract the contents and place them in a new jar, the signature is invalid and Java won't accept them. So you should either remove the signatures, or resign the entire jar that your artifact produces.
I have found that what is solution for this. I should not import the dependencies as a folder. I have to import them by select all the jar files instead of the folder of the jar files.

Adding External jar copy to Project

I created a project but I am using an external library for it. enter link description here
I added the library to my Beans as follows:
Right click on folder "Libraries"
Add Library
Create...
Gave it a name "gson 2.7"
Picked the class, source and javadoc files.
I went on and continued programming and then I added my code to Github. Then when I cloned it my Library was missing.
How can I fix this ? How can I make it dynamic so I dont have to worry about this anymore. In other words I need to add the library to my code and not just the reference.
Thanks a lot for the help
Just upload a copy of your library to github.
I have not used netbeans, but from what I understand it adds the jar somewhere outside of your project directory, and it simply adds the location of the jar to your classpath. When you upload and then clone the project from github, the jars are not uploaded/cloned, and the project structure metadata for your project is also lost from netbeans.
My suggestion is to learn and start using a build tool like maven. It takes up the responsibility of adding your dependency libraries everytime, given that you have an internet connection. It also adds the libs to the target directory of your project folder, so you probably will need the internet connection only once. The libs will be uploaded and cloned back from the github repo everytime.
IDEs like eclipse have inbuilt support for maven, so you don't even have to worry about executing the mvn commands. Here's a tutorial that will get you intrigued - with the IDE that you prefer.
https://platform.netbeans.org/tutorials/nbm-maven-quickstart.html
Thanks a lot for all the replies and comments.
Technically there are two approaches to my problem. For this articular example I chose to copy the external jar files to my project.
1. Copy jar files to your project.
Go to project properties
Under Libraries folder make sure to set up a libraries folder by following the steps.
Add Library at the bottom ( you can create or import; since I already had gson in Netbeans I just imported it.)
Press ok to confirm and you are done!
2. Use Maven
Go to plugings and make sure you have all Maven plugins installed, if not do so.
Create an new project and choose maven/java application
Follow the prompts
At this point you can start coding (in my case I just imported my class files from the other project)
Right click in "Dependencies folder and then "Add Dependency"
Under query type the repository you are looking for; in my case "com.google.code.gson : gson : 2.7"
Click add and you are done!
Thanks a lot to everyone for the help :)

Importing JSON into an Netbeans project

I need to import JSON library into netbeans.
How can I do that?
I searched on internet and I found this article.
According to this article when I import
import org.json.simple.JSONArray;
import org.json.simple.JSONObject
that, it must be work. But unfortunately it didn't work. and I get an error:
Package doesnt exist
Thanks for your help.
As the article says you need to add the simple-json library to your project:
http://code.google.com/p/json-simple/
For this we have to add Class org.json.JSONObject which available in json-20131018.jar.
We need to download this jar and add this jar to your buildpath.
for it in netbeans right click 'libraries' in the project list, then click add jar/folder.
Download jar from here : https://code.google.com/archive/p/json-simple/downloads
And then add it to your "libraries" in netbeans.
Added this answer, because other answer didn't provide the above link, which is the easiest to download jar from.
try add json-20131018.jar. This solved my problem.
http://mvnrepository.com/artifact/org.json/json/20131018
Or, instead of relying on the old version which uses the old import, use the newer version with the new import:
import com.github.cliftonlabs.json_simple.*;
For Netbeans, you can right click the project and go into Libraries to make sure the jar file is added into Classpath (not Modulepath). Press the '+' button to add it under that section by either by using a created library with the build jar and javadoc jar or, more simply, just adding the single jar file (json-simple-3.1.1.jar) directly to the classpath.
After doing this, the jar file should show up in the 'Libraries' folder under the project.

Use external project in JSP

I downloaded a project from Google Code named 'mp4parser'.
Now I want to use it in my JSP page (specifically in a servlet).
How do I import it?
I use Netbeans.
In my project's properties I added a Library (Add JAR/Folder).
Then, in my servlet code I wrote
import com.googlecode.mp4parser.*;
But I get an error 'package don't exist'.
SOLVED
First I had to compile the mp4parser project, and then MANUALLY indicate the JAR file.
Netbeans couldn't find it on its own.
You should create jar of the project you downloaded and the add it to the class path and then you will be able to use it.
So you get compile time error ? The only problem that is happeing is your Jar is not in the Build Path. Please check How to add jar in netbeans

NetBeans error: package org does not exist

I just installed Netbeans IDE. I am now unable to import any org.* libs and it just says package org does not exist.
Also, I imported jdic.jar into the project and even though the code completion suggestions show up as org.jdesktop.*, it shows the same error.
How do I fix this?
Clearing the cache fixed it.
In windows 7 the cache is located in
C:\Users\username\AppData\Local\NetBeans\...
On Linux, the cache is at:
/home/username/.cache/netbeans/...
On clearing the cache, and restarting netbeans, it started to recognize org.* imports again.
I did it easily, just click the Jframe, on Navigator tab, right-click -> Set Layout -> Absolute Layout and YEP, It works for me.
org.netbeans.lib.awtextra is part of the AbsoluteLayout library. It should be added automatically by the ide whenever absolutelayout is used in the form. But if you switch to some other layout after using absolute layout, then the jar/library will be removed from the classpath and existing code making calls to the library will not compile.
If you would like to use absolute layout, then please include the library in the project. Select 'Libraries' node in the project, right-click and select 'Add Library' and select 'Absolute Layout' library from the list of available libraries.
If you do not wish to use absolute layout, then it is best to uncomment/remove code relying on the library and re-do the form design using the new layout.
Can you try importing
import org.xml.sax.Attributes;
This is part of the JDK. If you can't find that, something is really wrong.
I suspect you need to add the libraries to your maven pom.xml file.
You should redirect all the lost .jar files by exiting netbeans, then reopening it. There should be a prompt asking you to help the IDE find the .jar files. So please do so. If you aren't able to find the jar file. Clean and build the individual packages. There a new directory called a dist directory will be created in the package directory. Now you can redirect them.
Above was not working for me so I tried below and its working:
Google "absolutelayout.jar download"
Download jar
Open NetBeans and Add this "AbsoluteLayout-RELEASE***.jar" file to your project Library folder.
now try to run the project/file
in my experience the problem was with a Jpanel with AbsoluteLayout, I put free-design and solved the problem

Categories

Resources