I'm working on a Java project that exec Ant target task on runtime.
On my pom file I have this dependency:
pom.xml
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>${ant.version}</version>
</dependency>
I have to run <scp> task that is included in a target container task (called scp-test-target).
Below you can see the ant file:
deploy.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" basedir="./">
<target name="scp-test-target" description="scp desc">
<echo message="Test SCP"/>
<scp file="..." todir="..."/>
</target>
</project>
I have created a junit file to exec 'scp-test-target':
Test.java
#Test
public void testAnt1(){
Project antProject = new Project();
ProjectHelper projectHelper = ProjectHelper.getProjectHelper();
antProject.addReference("ant.projectHelper", projectHelper);
antProject.setUserProperty("ant.file", "deploy.xml");
antProject.fireBuildStarted();
antProject.init();
projectHelper.parse(antProject, new File("deploy.xml"));
antProject.executeTarget("scp-test-target");
antProject.fireBuildFinished(null);
}
But when I run my junit test, the program failed because it not find jsch library.
Problem: failed to create task or type scp
Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.Scp was not found.
This looks like one of Ant's optional components.
So, how can I tell to Ant to link jsch libraries on my file system in programmatically way (so in my Test.java)?
Thanks in advance
Related
I'm getting an error when I try to wrap the Jar to exe through Launch4j.
I have added the library already in the NetBeans IDE and also for the Project but still the error persists.
The Jar is running without any problems but when I try to wrap it, I'm getting always that issue warning:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout
....
....
Caused by: java.lang.ClassNotFoundException: org.netbeans.lib.awtextra.AbsoluteLayout
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
How can I resolve this?
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="HelaTergo" default="default" basedir=".">
<description>Builds, tests, and runs the project HelaTergo.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="HelaTergo-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
CSS:
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Class-Path: lib/AbsoluteLayout.jar
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>C:\Users\ckoca\Documents\NetBeansProjects\HelaTergo\dist\HelaTergo.jar</jar>
<outfile>C:\Users\ckoca\OneDrive - COMPUTACENTER\Desktop\SerkoBib.exe</outfile>
<errTitle>Bitte Java vorerst installieren</errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>C:\Users\ckoca\Documents\Icons\Icons8-Windows-8-Business-Department.ico</icon>
<classPath>
<mainClass>helaTergo.HomeHelaTergo</mainClass>
<cp>lib/AbsoluteLayout.jar</cp>
</classPath>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.6.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>1.0.0.0</txtFileVersion>
<fileDescription>Serko Library Software</fileDescription>
<copyright>Computacenter</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>SerkoBib</productName>
<companyName>Computacenter</companyName>
<internalName>SerkoBib</internalName>
<originalFilename>SerkoBib.exe</originalFilename>
<trademarks></trademarks>
<language>ENGLISH_US</language>
</versionInfo>
</launch4jConfig>
I am using Eclipse Mars to run my Java project. I am making use of Maven in it. But while trying to compile my package I am getting the following error.
Failed to execute goal on project apex-check: Could not resolve dependencies for project org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0: Failed to collect dependencies at org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Failed to read artifact descriptor for org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Could not transfer artifact org.fundacionjala.enforce.sonarqube:apex-squid:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): Failed to authenticate with proxy -> [Help 1].
I am able to find that my pom.xml has a bug in its dependency. But don't know how to resolve it. I have given below my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright (c) Fundacion Jala. All rights reserved. ~ Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fundacionjala.enforce.sonarqube</groupId>
<artifactId>apex</artifactId>
<version>1.0b${build.number}</version>
</parent>
<artifactId>apex-check</artifactId>
<name>Apex :: Checks</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apex-squid</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
I have written 'apex-check' and 'apex-squid' as two separate projects.
Can anyone explain how to correct my pom.xml?
You need to have:
org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0
org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0
jar files available in your local .m2/repository folder. If they are not present maven will try to download from central repository and as an expected result it will fail on firewall or it will not find the artifact. i.e. if:
apex-check requires apex-squid project as dependency first you need to install squid project files by using mvn install on squid project folder.
But it seems more like you want to create a multi module maven project, take a look at this question. Create a parent project similar to this project, add check and squid as module and run mvn clean install on parent.
**edit: I just see you already have parent, so make sure parent has your projects as modules, which helps reactive build order and eclipse imports
I am using testng-6.8.21.jar for writing test case from the following link:
http://www.tutorialspoint.com/testng/testng_tutorial.pdf
I am able to compile the java file TestNGSimpleTest.java
but when I try to use this command:
java -cp "C:\TestNG_WORKSPACE" org.testng.TestNG testng.xml
it says:
could not find or load main class org.tesng.TestNG
You must provide full path to the jars in the classpath. For example :
java -cp '/path/to/testng-6.8.8.jar' org.testng.TestNG testng.xml
But testng requires other dependencies that you also must include in the classpath :
\- org.testng:testng:jar:6.1.1:test
+- junit:junit:jar:3.8.1:test
+- org.beanshell:bsh:jar:2.0b4:test
+- com.beust:jcommander:jar:1.12:test
\- org.yaml:snakeyaml:jar:1.6:test
The easiest way is to use a dependency manager. For example, Maven.
Briefly, you need (not required but it makes everything easier) to have a standard project structure :
main-directory
pom.xml <- File required by maven. It always has this name.
-src
-main
-java <- Place your Java classes here
-resources <- Place your images, conf files here etc.
-test
-java <- Place your java test classes here
-resources <- Place your test resources here.
Then, with this simple pom.xml, Maven understand that you want testng and downloads testNG's dependencies :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>my-app-name</artifactId>
<version>1.0.0-SNAPSHOT</version>
<!-- Declare your dependencies here-->
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Then launch :
mvn test
And if you want to have a view on the dependencies, use :
mvn dependency:tree
(This is how I got the preceding dependency tree)
I am using the maven-jspc-plugin in my pom.xml.
When i try to execute the jsp-compile goal (which executes the plugin) I get:
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.juli.logging.Slf4jLog.<init>(Slf4jLog.java:29)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:54)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:35)
at org.apache.sling.scripting.jsp.jasper.compiler.OriginalTldLocationsCache.<init>(OriginalTldLocationsCache.java:81)
at org.apache.sling.maven.jspc.JspcMojo.initServletContext(JspcMojo.java:426)
I've tried downloading the (open) source for the maven-jspc-plugin and i am able to easily "mvn install" -- I don't get any build issues, however when i use that build in my project pom it still crashes and tells me it can't find LoggerFactory.
I've logged an issue with the Apache Sling project but am not making much headway.
https://issues.apache.org/jira/browse/SLING-2350
This link includes some more troubleshooting info as well as a simple maven project that uses the maven plugin. downloading the jspc-test.zip and "mvn install"ing will result in the error I've mentioned.
Also, i took a peak at the org.apache.juli pom.xml and it doesnt appear to list any dependencies at all.
Any thoughts on how to resolve would be appreciated.
Thanks!
Plugin dependencies are supplied in a different part of the POM:
<project>
<dependencies>
<!-- dependencies defined here don't get included for plugins -->
...
</dependencies>
<build>
<plugins>
<plugin>
.... jspc plugin section ....
<dependencies>
<dependency>
<!-- Try adding slf4j here --->
Though it does sounds like their POM is invalid if it doesn't already specify slf4j.
I have tried invoking Ant programmatically, but I am encountering this error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/AntMain
I tried to run build.xml separately using the console and via right-clicking it in eclipse running as ant build. It runs with no problems.
My sample ant testing class
public class AntTest {
public static void main(String[] args) {
File buildFile = new File("build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
}
}
My sample build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="testproject" default="test" basedir=".">
<target name="test">
<echo message="Hello World" />
</target>
</project>
What am I missing?
Make sure that the ant libraries are in your classpath.
It seems, that ant-launcher-VERSION.jar (where Version is the ant version you are using) is missing in your classpath.