How to create a processing library from pde files - java

I have this nice set of processing .pde files that together would make a good library. I don't want to use Eclipse or some other GUI editor. I'm ok with Ant if need be.
To create a processing library, I need to put a jar file in the processing libraries folder (with some special naming conventions). I can create a .java files from the .pde files by exporting the application. If I modify these a bit, I can compile them using javac, but it needs to import processing.core.*;. I point it at my own processing core.jar, but at this point I get a
class file has wrong version
It seems processings core.jar was created for a different version of javac then I'm currently running.
So here's the question: am I totally off track and is there a better way to do this, or should I continue and download the Processing source code and compile it myself, in order to be compatible with my javac ?

I highly recommend using Eclipse or Intellij rather than the Processing editor. The Processing editor is great for writing sketches, but if you're building a library, you should probably use a more advanced IDE.
But it sounds like you're using an old version of Java and should upgrade. I'm pretty sure Processing is compatible with Java 8, which means you're using Java 7 or older. Java 7 has been end of life for quite some time now, and you should upgrade anyway.
To find out which Java you're using, try this command:
javac -version

Related

VSCode doesn't automatically generate .class file for java

I'm new to java and learned that when creating a .java file usually there's a .class file generated automatically, which happened to the previous java files I created.
However, I forgot since when VSCode stops doing this when I create new java file.
Another problem is, when creating a new java file, the shortcut to type "main" and press enter doesn't generate
public static void main(String[] args) {
}
anymore. I have to literally type out the whole thing, otherwise I have to close this new file, open again, wait a few seconds to half a min or so for the shortcut to work.
Any reason why?
The .class file is generated by compiling the .java file. The following settings in settings.json control the generation of .class files in the bin directory.
"java.project.outputPath": "bin",
In addition, you need to download the Extension Pack for Java, read the official document for more help.
Also check the following settings to control the location of code snippet suggestions.
"editor.snippetSuggestions": "inline",
Sounds like you've used some sort of IDE before, maybe IntelliJ or Eclipse.
The .class files
The .class files are compiled Java source files, containing JVM bytecode. These are generated when you build your Java program, either via a build tool (Maven, Gradle, Ant, etc..) or by compiling the sources. Now, if you use an IDE in most cases the IDE will take care of building your project. If you use the stock VSCode without any Java related plugins, VSCode doesn't know how to build a Java project out of the box. I believe you can define a build task, and run that, but it doesn't support it out-of-the-box, without any plugins. So you should look around in the VSCode plugin marketplace what Java-experience-enhancing plugins you can add.
Code snippets and shortcuts
Not sure why you have to reopen files for shortcuts to work. That being said, you're looking for code snippets, or IIRC IntelliJ calls these live-templates. These are, well, templates for code generation, which you can invoke in your editor. IIRC VSCode doesn't have any Java related code snippets, you have to add them yourself or install a plugin that provides these. In IntelliJ, you have built in templates or snippets for stuff like the main function, for-each blocks, etc.. but again, IntelliJ is a JVM-focused IDE, a very good one too. VSCode is a really good tool, but you may have to install some plugins and add stuff in order to have the cosy IDE-like experience.

Netbeans javac command

I am relatively new to Netbeans and Java, when I compile a project in Netbeans is there a way to view the equivalent javac commands, ie what I would have to run command line to produce the same result?
I use Netbeans 7.3.1 and you can see the building/compiling process in the output windows when you're building the program. Netbeans (my version) uses ANT to build program, so it produces a .jar.
If you want to know more about the details of how they compile a project, you can take a look at ANT http://ant.apache.org/, it's an useful build tool.
On your computer go to C:\Program Files\Java\jdk(the version you use)\jre\bin.
In bin you will find the commands you can use at the Command Prompt.
As David pointed, Netbeans uses Ant as its build tool, this means it uses a tool to parse a script that describes how to build each part of your project.
If you consider a simple Java program that is made of a single class this may not be significant and you could probably build it manually in the command line. However, any significant project (anything that does any interesting work) will need to compile many files, build the archive structure and every other task related to packing your application.
So, for a short answer you would have to consider the context:
1 - a simple class - yes you can compile manualy reading the output from the console
2 - for a simple project (that means, many classes) - yes, but starts to gets complicated
3 - for a real project (that means, many classes and resources) - no, it is not viable (and this means reasonable and confortable) to do it manualy.
For more info on compiling Java programs (which I think is your real interest) you should check the Javac page for a start (find it here).

When would I use ant for Java web development?

I do not understand the purpose of ant. I read the introduction, but am missing the big picture. I know the following (or at least that I want to use them),
Java
jdbc
hibernate
jsp
servlet container like Tomcat
But I don't see how ant fits in.
Is there some all comprehensive tutorial that tells me how to put all this together?
Why would I want ant? What is the alternative if I don't have ant?
EDIT: So is this sort of the compiling part of its Visual Studio counterpart?
Ant is used as a build system. You do not have to use it--in fact there are quite a few better systems but since ant was one of the first it's still likely to be very common. It generally is used to compile your java files, create wars and often even put the .war files onto the tomcats.
Maven is bigger and tries to do a lot more, but it's also rather strict in it's format and quite heavy--but it's quite common these days as well. Maven can gather all your dependencies automatically which is nice, with ant you still have to download everything yourself.
There are others, but you get the idea.
Response to comment:
I don't use visual studio, but I think it is more limited. For instance, Eclipse can build all your java files into a jar or execute them directly (in fact, it uses ant internally). If you wanted to take your visual stuido "Build configuration" and put it into another tool (Perhaps an automated build system like Jenkins) that doesn't rely on visual studio directly, can you do so?
I guess Ant is the way we code our builds--it's portable betweeen many tools. Visual Studio would be cleaner to "create" your build, but "Exporting" the ability to build would be more difficult (if even possible).
Also ant is portable across operating systems as well as tools. We can switch from Eclipse to Netbeans to IntelliJ without touching our build toolchain.
How would you completely remove visual studio and replace it with slickedit, emacs or vi (if that was your thing, which I'm sure it's not) without starting over from scratch with your build?
For any web application to work you need to package or build all your java code with all the libraries into an web application archive to accomplish this task we need to some tool or library to package into the correct format and some of the libraries which can achieve this is
Apache Ant and Apache Maven
There some good discussions about Ant vs Maven in SO.
You need ant to build the project. Well you can build project using IDE like eclipse etc. But for production purpose and big projects, it always advisable to some build script like ant. Its a script where you can customize what you want to build and what not. you can define what is the output should be like war/jar/ear etc
Other alternative is Maven which is very prevalent and standard now a days

Is it possible to view dynamically generated bytecode in eclipse?

I know of several solutions for files that end in ".class", where you can use the ByteCode Outline plugin, or the Bytecode Visualiser plugin, or even the built-in "javap-like" viewer for classfiles.
But I would like this ability for runtime-generated code while debugging! What I am trying to achieve is to see the actual generated code from a clojure call executing. This uses ASM to generate classes on the fly.
Using the eclipse IDE, you can combine JAD(a java decompiler) with the JADClipse plugin to decompile your class files on the fly whenever the debugger attempts to open a class file that has no linked source. Without eclipse, you can use JAD as an independant executable, but it is less user friendly.
JAD will generate the java source for a class file even if it was built with a java assembler. This is possible because the java language is close enough to the functionality of the jvm. The only class files this wont work on is ones that have been run through an obfuscator to prevent decompilation
Apart from JAD, there are other tools. One's called JD (Java Decompiler). It also has an eclipse plugin and is a little better than JAD since it supports Java 5, JAD only supports Java 4 (as far as I know there hasn't been any development on JAD since 2001 or something). A tool that seems to be supporting Java 6 is DJ Java Decompiler, but I haven't tested that yet.
And I don't know if any of these tools actually support on-the-fly-generated code, on the other hand I don't really see why they should not.

Trouble installing Boilerpipe

This is the third time I've installed it. I had it working on Windows, and up until a few days ago on Linux. I've done all I can do and I don't understand how to run this Java program.
The source code is a folder with a lib, src some jars and a classpath and project file.
The classpath file makes some declarations like classpathentry=src/main and path=lib, path=src.
All of these make sense. There is a folder 'main' inside 'src'.
The tiny file I'm trying to run starts off by
import de.l3s.boilerpipe.demo
I'm trying to run 'Oneliner.java'. I cannot compile it.
No matter what/where that class file is, I cannot run it. It results in a noclassdeffound.
I've run it in the main, the src, the root, the demo, the ... anywhere.
I've tried compiling it in different directories, running it with various java command line switches that were recommended. Supposedly you can have it 'search' for the file, which I've yet to experience. The sheer stubbornness of this java environment is terrifying. And massively humiliating for me.
I had the same problem with installing it. The 'Getting Started' page is poor quality.
My solution was to use a python wrapper, which you can find here: https://github.com/misja/python-boilerpipe
It takes care of all of the dependencies you'll need (however, you might be missing jpype if you're on a Mac. In that case, you'll need to install it manually from: http://jpype.sourceforge.net/).
The best way to start using the boilerpipe algorithm (and to see what it is for) is to use the demo site:
http://boilerpipe-web.appspot.com/
If you want to integrate the boilerpipe library into your applications, or even intent to modify/improve the code, you will definitely need solid Java programming skills.
As a quick-start I suggest that you install a recent version of the Eclipse IDE for Java Developers and import boilerpipe-core as a project. This avoids pretty much of the classpath configuration, and almost everything should be set up correctly for you.
The classpath file you mentioned is probably ".classpath", which is part of the Eclipse project configuration. You don't need it unless you want an Eclipse project.

Categories