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).
Related
I am using a bash script to run my Java program that I made in Eclipse and the Java program is working fine when ran from Eclipse. It has my most recent changes which I can tell by some print statements that I just inserted and ran again.
However, these print statements and all my other changes are not being seen when I run my bash script, which literally just runs the program like this (using testNG):
java -cp ".\src\main\java;lib\*;" org.testng.TestNG ParallelTestXML.xml
I have already cleaned the project in Eclipse and made sure build automatically is clicked, although I think that is to fix if it isn't compiling recent changes within Eclipse. So I have no idea what else it could be.
Because .\src\main\java doesn't do anything useful.
Eclipse has this concept called 'builders' and 'project kinds', and depending on how you've set up your java project, eclipse's build-on-save architecture works differently.
Assuming you just went: "File > New Project > Java Project", and picked all the default options, the way eclipse is set up is that you have a src dir (the fact that you write src/main/java belies that you didn't do this, but I'll continue for the sake of example), and when you save any java file in eclipse, eclipse will immediately update a built view of this, and it will be in a dir hanging off of the project root called bin.
That's where the class files live, so if you want to run off of those on the command line, the right move is:
java -cp ".\bin;lib\*;" org.testng.TestNG ParallelTestXML.xml
Adding the src dir is completely pointless, unless the class files live right next to the source files, in which case calling that dir src is obviously very silly (as a general rule in programming, picking a name that clearly lies, is a very bad idea, for obvious reasons).
If you have some other project setup, for example, you've set it up as a maven project or a gradle project, well, it depends on how you configured eclipse whether eclipse is trying to 'match' the builds, or is triggering a full maven build every time you save, or if you're supposed to invoke maven manually. Most likely the latter. Let maven do the building, and maven will then build your stuff someplace. Generally, {projroot}\target\classes, but to 'run' your app if your app is built with maven, don't invoke java. invoke mvn, asking it to test your stuff. That way mvn will take care of your deps and the like.
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
I usually compile and execute from Java project using eclipse IDE. Now, I need to write a bash script to submit this task to a cluster. My project contains 3 packages and has been written as per the Maven architecture. Can anyone hint me as to how can I include the task of executing the java program in the my bash script?
I tried different things like first trying to execute the project using command line but it does not work. I already read the replies provided in this post: Compiling and running multiple packages using the command line in Java and some others, but didn't help.
Thank you for your help.
I strongly suggest you look into something like the Maven App Assembler plugin. I don't know about your cluster but the mentioned plugin can create run scripts for most major OSes and is highly configurable.
I have a vague memory that I've seen a build system for Java or some other JVM lang which you could run in continous mode (so to speak). This would make the build system run in the background, watching the source dir for changes. As soon as a source file changes, the build system kicks in and re-runs relevant parts of the build process to produce a fresh artifact.
Ring any bells?
Thanks
Is it the gradle daemon?
This keeps gradle running in the background because it has long start up times - and scans the file system to identify when files change.
There are lots of engines that support continual checkouts/building/testing (e.g. Jenkins nee Hudson, CruiseControl, TeamCity etc.).
If you're looking at JVM languages other than Java, then (for example) the Maven Scala plugin supports continuous building and testing upon file changes. e.g.
$ mvn scala:cctest
will run the compile/test cycle in a loop watching for source changes and acting upon them.
If your build tool or language doesn't support this natively, it's trivial to write a shell script to watch a directory structure and execute another script/tool upon change. See this SO question for solutions.
I figured out that it was in fact sbt that I meant. There is another question here on SO relating to how to build Java projects: Use SBT to Build Pure Java Project. Thanks everyone for your help.
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.